當前位置: 首頁>>代碼示例>>Python>>正文


Python win32api.SetConsoleCtrlHandler方法代碼示例

本文整理匯總了Python中win32api.SetConsoleCtrlHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python win32api.SetConsoleCtrlHandler方法的具體用法?Python win32api.SetConsoleCtrlHandler怎麽用?Python win32api.SetConsoleCtrlHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32api的用法示例。


在下文中一共展示了win32api.SetConsoleCtrlHandler方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: stop

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def stop(self):
        if not self.is_set:
            self.bus.log('Handler for console events already off.', level=20)
            return

        try:
            result = win32api.SetConsoleCtrlHandler(self.handle, 0)
        except ValueError:
            # "ValueError: The object has not been registered"
            result = 1

        if result == 0:
            self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' %
                         win32api.GetLastError(), level=40)
        else:
            self.bus.log('Removed handler for console events.', level=20)
            self.is_set = False 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:19,代碼來源:win32.py

示例2: DebugService

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def DebugService(cls, argv = []):
    # Run a service in "debug" mode.  Re-implements what pythonservice.exe
    # does when it sees a "-debug" param.
    # Currently only used by "frozen" (ie, py2exe) programs (but later may
    # end up being used for all services should we ever remove
    # pythonservice.exe)
    import servicemanager
    global g_debugService

    print "Debugging service %s - press Ctrl+C to stop." % (cls._svc_name_,)
    servicemanager.Debugging(True)
    servicemanager.PrepareToHostSingle(cls)
    g_debugService = cls(argv)
    # Setup a ctrl+c handler to simulate a "stop"
    win32api.SetConsoleCtrlHandler(_DebugCtrlHandler, True)
    try:
        g_debugService.SvcRun()
    finally:
        win32api.SetConsoleCtrlHandler(_DebugCtrlHandler, False)
        servicemanager.Debugging(False)
        g_debugService = None 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,代碼來源:win32serviceutil.py

示例3: stop

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def stop(self):
        if not self.is_set:
            self.bus.log('Handler for console events already off.', level=40)
            return

        try:
            result = win32api.SetConsoleCtrlHandler(self.handle, 0)
        except ValueError:
            # "ValueError: The object has not been registered"
            result = 1

        if result == 0:
            self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' %
                         win32api.GetLastError(), level=40)
        else:
            self.bus.log('Removed handler for console events.', level=40)
            self.is_set = False 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:19,代碼來源:win32.py

示例4: stop

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def stop(self):
        if not self.is_set:
            self.bus.log('Handler for console events already off.', level=40)
            return
        
        try:
            result = win32api.SetConsoleCtrlHandler(self.handle, 0)
        except ValueError:
            # "ValueError: The object has not been registered"
            result = 1
        
        if result == 0:
            self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' %
                         win32api.GetLastError(), level=40)
        else:
            self.bus.log('Removed handler for console events.', level=40)
            self.is_set = False 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:19,代碼來源:win32.py

示例5: start

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def start(self):
        if self.is_set:
            self.bus.log('Handler for console events already set.', level=20)
            return

        result = win32api.SetConsoleCtrlHandler(self.handle, 1)
        if result == 0:
            self.bus.log('Could not SetConsoleCtrlHandler (error %r)' %
                         win32api.GetLastError(), level=40)
        else:
            self.bus.log('Set handler for console events.', level=20)
            self.is_set = True 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:14,代碼來源:win32.py

示例6: __call_service_handler

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def __call_service_handler():
    def __ctrlHandler(ctrlType):
        return True
    
    
    from opsbro.windows_service.windows_service import Service
    win32api.SetConsoleCtrlHandler(__ctrlHandler, True)
    win32serviceutil.HandleCommandLine(Service) 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:10,代碼來源:cli.py

示例7: set_exit_handler

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def set_exit_handler(self):
        func = self.manage_signal
        if os.name == "nt":
            try:
                import win32api
                
                win32api.SetConsoleCtrlHandler(func, True)
            except ImportError:
                version = ".".join(map(str, sys.version_info[:2]))
                raise Exception("pywin32 not installed for Python " + version)
        else:
            for sig in (signal.SIGTERM, signal.SIGINT, signal.SIGUSR1, signal.SIGUSR2):
                signal.signal(sig, func) 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:15,代碼來源:cluster.py

示例8: start

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def start(self):
        if self.is_set:
            self.bus.log('Handler for console events already set.', level=40)
            return

        result = win32api.SetConsoleCtrlHandler(self.handle, 1)
        if result == 0:
            self.bus.log('Could not SetConsoleCtrlHandler (error %r)' %
                         win32api.GetLastError(), level=40)
        else:
            self.bus.log('Set handler for console events.', level=40)
            self.is_set = True 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:14,代碼來源:win32.py

示例9: start

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def start(self, open_ui=False):
        async_fire_and_forget(self.async_start(open_ui=open_ui), self.loop)

        # Windows does not seem to handle Ctrl+C well so as a workaround
        # register a handler and manually stop the app
        if sys.platform == 'win32':
            import win32api

            def handle_win32_interrupt(sig, func=None):
                self.stop()
                return True

            win32api.SetConsoleCtrlHandler(handle_win32_interrupt, 1)

        try:
            self.loop.run_forever()
        except KeyboardInterrupt:
            self.loop.call_soon_threadsafe(self.loop.create_task,
                                           self.async_stop())
            self.loop.run_forever()
        except:
            # Catch all other exceptions and terminate the application. The loop
            # exeception handler will take care of logging the actual error and
            # LedFx will cleanly shutdown.
            self.loop.run_until_complete(self.async_stop(exit_code = -1))
            pass
        finally:
            self.loop.stop()
        return self.exit_code 
開發者ID:ahodges9,項目名稱:LedFx,代碼行數:31,代碼來源:core.py

示例10: start

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import SetConsoleCtrlHandler [as 別名]
def start(self):
        if self.is_set:
            self.bus.log('Handler for console events already set.', level=40)
            return
        
        result = win32api.SetConsoleCtrlHandler(self.handle, 1)
        if result == 0:
            self.bus.log('Could not SetConsoleCtrlHandler (error %r)' %
                         win32api.GetLastError(), level=40)
        else:
            self.bus.log('Set handler for console events.', level=40)
            self.is_set = True 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:14,代碼來源:win32.py


注:本文中的win32api.SetConsoleCtrlHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。