本文整理汇总了Python中sys.exitfunc方法的典型用法代码示例。如果您正苦于以下问题:Python sys.exitfunc方法的具体用法?Python sys.exitfunc怎么用?Python sys.exitfunc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.exitfunc方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_comments
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def test_comments(self):
b = """
import sys # Foo
sys.exitfunc = f # Blah
"""
a = """
import sys
import atexit # Foo
atexit.register(f) # Blah
"""
self.check(b, a)
b = """
import apples, sys, crumbs, larry # Pleasant comments
sys.exitfunc = func
"""
a = """
import apples, sys, crumbs, larry, atexit # Pleasant comments
atexit.register(func)
"""
self.check(b, a)
示例2: start
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def start(argv=None):
sys.exitfunc = lambda: sys.stderr.write("Shutting down...\n")
if argv is None:
argv = [
"nosetests", "--cover-branches", "--with-coverage",
"--cover-erase", "--verbose",
"--cover-package=django_drf_filepond",
]
# argv = [
# "nosetests", "--cover-branches", "--verbose",
# "--cover-package=django_drf_filepond",
# ]
nose.run_exit(argv=argv,
defaultTest=os.path.abspath(os.path.dirname(__file__)))
示例3: FoundPost
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def FoundPost(self, pkt):
try:
if pkt.load != None:
self.PostPackages += 1
self.ExtractInfo(pkt, 'Post')
except Exception, e:
e = str(e)
if 'load' not in e:
self.PostPackages -= 1
if 'byte' not in e:
print '\n[X]%s' %putColor('Something went wrong', 'red'), ' '*100, '\n'
print putColor(traceback.format_exc(), 'white')
sys.exitfunc = self.Exit
sys.exit(1)
示例4: test_sys_override
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [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")
示例5: exec_
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [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)
示例6: test_simple
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def test_simple(self):
b = """
import sys
sys.exitfunc = my_atexit
"""
a = """
import sys
import atexit
atexit.register(my_atexit)
"""
self.check(b, a)
示例7: test_names_import
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def test_names_import(self):
b = """
import sys, crumbs
sys.exitfunc = my_func
"""
a = """
import sys, crumbs, atexit
atexit.register(my_func)
"""
self.check(b, a)
示例8: test_complex_expression
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def test_complex_expression(self):
b = """
import sys
sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
"""
a = """
import sys
import atexit
atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
"""
self.check(b, a)
示例9: test_in_a_function
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def test_in_a_function(self):
b = """
import sys
def f():
sys.exitfunc = func
"""
a = """
import sys
import atexit
def f():
atexit.register(func)
"""
self.check(b, a)
示例10: test_unchanged
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def test_unchanged(self):
s = """f(sys.exitfunc)"""
self.unchanged(s)
示例11: test_no_sys_import
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [as 别名]
def test_no_sys_import(self):
b = """sys.exitfunc = f"""
a = """atexit.register(f)"""
msg = ("Can't find sys import; Please add an atexit import at the "
"top of your file.")
self.warns(b, a, msg)
示例12: test_sys_override
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exitfunc [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")