本文整理汇总了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]
示例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)
示例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")
示例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")
示例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")
示例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
示例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)
示例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)
示例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
示例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")
示例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)
示例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")
示例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")
示例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)
示例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