当前位置: 首页>>代码示例>>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;未经允许,请勿转载。