本文整理匯總了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")