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


Python atexit._run_exitfuncs方法代碼示例

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


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

示例1: handle

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def handle(self, signum=0, sframe=None):
        self.received += 1

        # code snippet adapted from atexit._run_exitfuncs
        exc_info = None
        for i in xrange(self.received).__reversed__():
            for handler in self.handlers.get(i, []).__reversed__():
                try:
                    handler(signum, sframe)
                except SystemExit:
                    exc_info = sys.exc_info()
                except:
                    import traceback
                    print >> sys.stderr, "Error in SignalHandler.handle:"
                    traceback.print_exc()
                    exc_info = sys.exc_info()

        if exc_info is not None:
            raise exc_info[0], exc_info[1], exc_info[2] 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:subproc.py

示例2: test_print_tracebacks

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def test_print_tracebacks(self):
        # Issue #18776: the tracebacks should be printed when errors occur.
        def f():
            1/0  # one
        def g():
            1/0  # two
        def h():
            1/0  # three
        atexit.register(f)
        atexit.register(g)
        atexit.register(h)

        self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs)
        stderr = self.stream.getvalue()
        self.assertEqual(stderr.count("ZeroDivisionError"), 3)
        self.assertIn("# one", stderr)
        self.assertIn("# two", stderr)
        self.assertIn("# three", stderr) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:20,代碼來源:test_atexit.py

示例3: test_args

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [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

示例4: test_order

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [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

示例5: test_sys_override

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [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

示例6: test_raise

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [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

示例7: exec_

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def exec_(argv):  # never returns
    """Wrapper to os.execv which shows the command and runs any atexit handlers (for coverage's sake).
    Like os.execv, this function never returns.
    """
    # info('EXEC' + colorize(argv))  # TODO: debug logging by environment variable

    # in python3, sys.exitfunc has gone away, and atexit._run_exitfuncs seems to be the only pubic-ish interface
    #   https://hg.python.org/cpython/file/3.4/Modules/atexitmodule.c#l289
    import atexit
    atexit._run_exitfuncs()

    from os import execv
    execv(argv[0], argv) 
開發者ID:edmundmok,項目名稱:mealpy,代碼行數:15,代碼來源:venv_update.py

示例8: run

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def run(self, cmd, globalsDict=None, localsDict=None, debug=True):
        """Starts a given command under debugger control"""
        if globalsDict is None:
            import __main__
            globalsDict = __main__.__dict__

        if localsDict is None:
            localsDict = globalsDict

        if not isinstance(cmd, types.CodeType):
            cmd = compile(cmd, "<string>", "exec")

        if debug:
            # First time the trace_dispatch function is called, a "base debug"
            # function has to be returned, which is called at every user code
            # function call. This is ensured by setting stop_everywhere.
            self.stop_everywhere = True
            sys.settrace(self.trace_dispatch)

        try:
            exec(cmd, globalsDict, localsDict)
            atexit._run_exitfuncs()
            self._dbgClient.progTerminated(0)
        except SystemExit:
            atexit._run_exitfuncs()
            excinfo = sys.exc_info()
            exitcode, message = self.__extractSystemExitMessage(excinfo)
            self._dbgClient.progTerminated(exitcode, message)
        except Exception:
            excinfo = sys.exc_info()
            self.user_exception(excinfo, True)
        finally:
            self.quitting = True
            sys.settrace(None) 
開發者ID:SergeySatskiy,項目名稱:codimension,代碼行數:36,代碼來源:base_cdm_dbg.py

示例9: exit

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def exit():
    """
    Causes python to exit without garbage-collecting any objects, and thus avoids
    calling object destructor methods. This is a sledgehammer workaround for 
    a variety of bugs in PyQt and Pyside that cause crashes on exit.
    
    This function does the following in an attempt to 'safely' terminate
    the process:
    
    * Invoke atexit callbacks
    * Close all open file handles
    * os._exit()
    
    Note: there is some potential for causing damage with this function if you
    are using objects that _require_ their destructors to be called (for example,
    to properly terminate log files, disconnect from devices, etc). Situations
    like this are probably quite rare, but use at your own risk.
    """
    
    ## first disable our own cleanup function; won't be needing it.
    setConfigOptions(exitCleanup=False)
    
    ## invoke atexit callbacks
    atexit._run_exitfuncs()
    
    ## close file handles
    if sys.platform == 'darwin':
        for fd in range(3, 4096):
            if fd not in [7]:  # trying to close 7 produces an illegal instruction on the Mac.
                os.close(fd)
    else:
        os.closerange(3, 4096) ## just guessing on the maximum descriptor count..

    os._exit(0)
    


## Convenience functions for command-line use 
開發者ID:SrikanthVelpuri,項目名稱:tf-pose,代碼行數:40,代碼來源:__init__.py

示例10: test_args

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def test_args(self):
        atexit.register(self.h1)
        atexit.register(self.h4)
        atexit.register(self.h4, 4, kw="abc")
        atexit._run_exitfuncs()
        self.assertEqual(self.subst_io.getvalue(),
                         "h4 (4,) {'kw': 'abc'}\nh4 () {}\nh1\n") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_atexit.py

示例11: test_badargs

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def test_badargs(self):
        atexit.register(lambda: 1, 0, 0, (x for x in (1,2)), 0, 0)
        self.assertRaises(TypeError, atexit._run_exitfuncs) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:test_atexit.py

示例12: test_order

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def test_order(self):
        atexit.register(self.h1)
        atexit.register(self.h2)
        atexit.register(self.h3)
        atexit._run_exitfuncs()
        self.assertEqual(self.subst_io.getvalue(), "h3\nh2\nh1\n") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_atexit.py

示例13: test_sys_override

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_atexit.py

示例14: test_raise

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def test_raise(self):
        atexit.register(self.raise1)
        atexit.register(self.raise2)
        self.assertRaises(TypeError, atexit._run_exitfuncs) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_atexit.py

示例15: test_raise

# 需要導入模塊: import atexit [as 別名]
# 或者: from atexit import _run_exitfuncs [as 別名]
def test_raise(self):
        atexit.register(self.raise1)
        atexit.register(self.raise2)
        self.assertRaises(TypeError, atexit._run_exitfuncs)

    ### helpers 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:8,代碼來源:test_atexit.py


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