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