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


Python atexit._exithandlers方法代碼示例

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


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

示例1: test_args

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def test_args(self):
        # be sure args are handled properly
        s = StringIO.StringIO()
        sys.stdout = sys.stderr = s
        save_handlers = atexit._exithandlers
        atexit._exithandlers = []
        try:
            atexit.register(self.h1)
            atexit.register(self.h4)
            atexit.register(self.h4, 4, kw="abc")
            atexit._run_exitfuncs()
        finally:
            sys.stdout = sys.__stdout__
            sys.stderr = sys.__stderr__
            atexit._exithandlers = save_handlers
        self.assertEqual(s.getvalue(), "h4 (4,) {'kw': 'abc'}\nh4 () {}\nh1\n") 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:18,代碼來源:test_atexit.py

示例2: test_order

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def test_order(self):
        # be sure handlers are executed in reverse order
        s = StringIO.StringIO()
        sys.stdout = sys.stderr = s
        save_handlers = atexit._exithandlers
        atexit._exithandlers = []
        try:
            atexit.register(self.h1)
            atexit.register(self.h2)
            atexit.register(self.h3)
            atexit._run_exitfuncs()
        finally:
            sys.stdout = sys.__stdout__
            sys.stderr = sys.__stderr__
            atexit._exithandlers = save_handlers
        self.assertEqual(s.getvalue(), "h3\nh2\nh1\n") 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:18,代碼來源:test_atexit.py

示例3: test_sys_override

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        s = StringIO.StringIO()
        sys.stdout = sys.stderr = s
        save_handlers = atexit._exithandlers
        atexit._exithandlers = []
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.stdout = sys.__stdout__
            sys.stderr = sys.__stderr__
            atexit._exithandlers = save_handlers
            sys.exitfunc = exfunc
        self.assertEqual(s.getvalue(), "h2\nh1\n") 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:20,代碼來源:test_atexit.py

示例4: test_raise

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def test_raise(self):
        # be sure raises are handled properly
        s = StringIO.StringIO()
        sys.stdout = sys.stderr = s
        save_handlers = atexit._exithandlers
        atexit._exithandlers = []
        try:
            atexit.register(self.raise1)
            atexit.register(self.raise2)
            self.assertRaises(TypeError, atexit._run_exitfuncs)
        finally:
            sys.stdout = sys.__stdout__
            sys.stderr = sys.__stderr__
            atexit._exithandlers = save_handlers

    ### helpers 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:18,代碼來源:test_atexit.py

示例5: setUp

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def setUp(self):
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        self.stream = StringIO.StringIO()
        sys.stdout = sys.stderr = self.subst_io = self.stream
        self.save_handlers = atexit._exithandlers
        atexit._exithandlers = [] 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_atexit.py

示例6: tearDown

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def tearDown(self):
        sys.stdout = self.save_stdout
        sys.stderr = self.save_stderr
        atexit._exithandlers = self.save_handlers 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_atexit.py

示例7: setUp

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def setUp(self):
        s = StringIO.StringIO()
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        sys.stdout = sys.stderr = self.subst_io = s
        self.save_handlers = atexit._exithandlers
        atexit._exithandlers = [] 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:9,代碼來源:test_atexit.py

示例8: init_error_client

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def init_error_client():
    """ Send traceback to neuropoly servers

    :return:
    """
    if os.getenv('SENTRY_DSN'):
        logger.debug('Configuring sentry report')
        try:
            client = raven.Client(
             release=__version__,
             processors=(
              'raven.processors.RemoveStackLocalsProcessor',
              'raven.processors.SanitizePasswordsProcessor'),
            )
            server_log_handler(client)
            traceback_to_server(client)

            old_exitfunc = sys.exitfunc
            def exitfunc():
                sent_something = False
                try:
                    # implementation-specific
                    import atexit
                    for handler, args, kw in atexit._exithandlers:
                        if handler.__module__.startswith("raven."):
                            sent_something = True
                except:
                    pass
                old_exitfunc()
                if sent_something:
                    print("Note: you can opt out of Sentry reporting by editing the file ${SCT_DIR}/bin/sct_launcher and delete the line starting with \"export SENTRY_DSN\"")

            sys.exitfunc = exitfunc
        except raven.exceptions.InvalidDsn:
            # This could happen if sct staff change the dsn
            logger.debug('Sentry DSN not valid anymore, not reporting errors') 
開發者ID:neuropoly,項目名稱:spinalcordtoolbox,代碼行數:38,代碼來源:sct_utils.py

示例9: shutdown

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _exithandlers [as 別名]
def shutdown(self, force_quit_timeout=0):
        """
        Shutdown the queue (after finishing any pending requests).
        """
        self.logger.info('Shutting down threadpool')
        # Add a shutdown request for every worker
        for i in range(len(self.workers)):
            self.queue.put(ThreadPool.SHUTDOWN)
        # Wait for each thread to terminate
        hung_workers = []
        for worker in self.workers:
            worker.join(0.5)
            if worker.isAlive():
                hung_workers.append(worker)
        zombies = []
        for thread_id in self.dying_threads:
            if self.thread_exists(thread_id):
                zombies.append(thread_id)
        if hung_workers or zombies:
            self.logger.info("%s workers didn't stop properly, and %s zombies",
                             len(hung_workers), len(zombies))
            if hung_workers:
                for worker in hung_workers:
                    self.kill_worker(worker.thread_id)
                self.logger.info('Workers killed forcefully')
            if force_quit_timeout:
                hung = []
                timed_out = False
                need_force_quit = bool(zombies)
                for workers in self.workers:
                    if not timed_out and worker.isAlive():
                        timed_out = True
                        worker.join(force_quit_timeout)
                    if worker.isAlive():
                        print "Worker %s won't die" % worker
                        need_force_quit = True
                if need_force_quit:
                    import atexit
                    # Remove the threading atexit callback
                    for callback in list(atexit._exithandlers):
                        func = getattr(callback[0], 'im_func', None)
                        if not func:
                            continue
                        globs = getattr(func, 'func_globals', {})
                        mod = globs.get('__name__')
                        if mod == 'threading':
                            atexit._exithandlers.remove(callback)
                    atexit._run_exitfuncs()
                    print 'Forcefully exiting process'
                    os._exit(3)
                else:
                    self.logger.info('All workers eventually killed')
        else:
            self.logger.info('All workers stopped') 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:56,代碼來源:httpserver.py


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