Python sys 模块,exitfunc() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sys.exitfunc()

项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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)
项目:kibtool    作者:jpparis-orange    | 项目源码 | 文件源码
def run_all(argv=None):
  sys.exitfunc = lambda: sys.stderr.write('Shutting down....\n')

  # always insert coverage when running tests through setup.py
  if argv is None:
    argv = [
      'nosetests', '--with-xunit',
      '--logging-format=%(levelname)s %(name)22s %(funcName)22s:%(lineno)-4d %(message)s',
      '--with-xcoverage', '--cover-package=kibtool', '--cover-erase',
      '--verbose',
    ]

  nose.run_exit(
    argv=argv,
    defaultTest=abspath(dirname(__file__))
  )
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:mac-package-build    作者:persepolisdm    | 项目源码 | 文件源码
def test_scan_code__basic(monkeypatch, use_ast):
    code = """
    import os.path
    from sys import maxint, exitfunc, platform
    del exitfunc
    def testfunc():
        import shutil
    """
    module = __scan_code(code, use_ast, monkeypatch)
    assert len(module._deferred_imports) == 3
    assert ([di[1][0] for di in module._deferred_imports]
            == ['os.path', 'sys', 'shutil'])
    assert module.is_global_attr('maxint')
    assert module.is_global_attr('os')
    assert module.is_global_attr('platform')
    assert not module.is_global_attr('shutil') # not imported at module level
    assert not module.is_global_attr('exitfunc')
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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")
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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")
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s)
项目:isard    作者:isard-vdi    | 项目源码 | 文件源码
def run(self):
        # Close connection on exit (to test cleanup paths)
        self.tid = get_tid()
        log.info('starting thread: {} (TID {})'.format(self.name, self.tid))
        old_exitfunc = getattr(sys, 'exitfunc', None)

        def exit():
            log.info('Closing hypervisors connexions')
            for hyp_id, hostname in self.hyps.items():
                self.hyps_conn[hyp_id].close()
            if (old_exitfunc): old_exitfunc()

        sys.exitfunc = exit

        # self.r_status = RethinkHypEvent()

        self.thread_event_loop = virEventLoopNativeStart()

        for hyp_id, hostname in self.hyps.items():
            self.add_hyp_to_receive_events(hyp_id)

        while self.stop is not True:
            time.sleep(0.1)

        if self.stop is True:
            for hyp_id in self.hyps:
                self.del_hyp_to_receive_events(hyp_id)
项目:isard    作者:isard-vdi    | 项目源码 | 文件源码
def run(self):
        # Close connection on exit (to test cleanup paths)
        self.tid = get_tid()
        log.info('starting thread: {} (TID {})'.format(self.name, self.tid))
        old_exitfunc = getattr(sys, 'exitfunc', None)

        def exit():
            log.info('Closing hypervisors connexions')
            for hyp_id, hostname in self.hyps.items():
                self.hyps_conn[hyp_id].close()
            if (old_exitfunc): old_exitfunc()

        sys.exitfunc = exit

        # self.r_status = RethinkHypEvent()

        self.thread_event_loop = virEventLoopNativeStart()

        for hyp_id, hostname in self.hyps.items():
            self.add_hyp_to_receive_events(hyp_id)

        while self.stop is not True:
            time.sleep(0.1)

        if self.stop is True:
            for hyp_id in self.hyps:
                self.del_hyp_to_receive_events(hyp_id)
项目:django-chemtrails    作者:inonit    | 项目源码 | 文件源码
def start(argv=None):
    sys.exitfunc = lambda: sys.stderr.write('Shutting down...\n')

    if argv is None:
        argv = [
            'nosetests',
            '--verbose',
            '--with-coverage',
            '--cover-html', '--cover-html-dir=.htmlcov',
            '--cover-erase',
            '--cover-branches',
            '--cover-package=chemtrails',
        ]

    nose.run_exit(argv=argv, defaultTest=os.path.abspath(os.path.dirname(__file__)))
项目:django-hesab    作者:rhblind    | 项目源码 | 文件源码
def start(argv=None):
    sys.exitfunc = lambda: sys.stderr.write('Shutting down...\n')

    if argv is None:
        argv = [
            'nosetests',
            '--verbose',
            '--with-coverage',
            '--cover-html', '--cover-html-dir=.htmlcov',
            '--cover-erase',
            '--cover-branches',
            '--cover-package=hesab',
        ]

    nose.run_exit(argv=argv, defaultTest=os.path.abspath(os.path.dirname(__file__)))
项目:django-haystack-elasticsearch    作者:CraveFood    | 项目源码 | 文件源码
def run_all(argv=None):
    sys.exitfunc = lambda: sys.stderr.write('Shutting down....\n')

    # always insert coverage when running tests through setup.py
    if argv is None:
        argv = [
            'nosetests', '--with-coverage', '--cover-package=haystack_elasticsearch',
            '--cover-erase', '--verbose',
        ]

    nose.run_exit(
        argv=argv,
        defaultTest=abspath(dirname(__file__))
    )
项目:gdata-python3    作者:dvska    | 项目源码 | 文件源码
def report(*args, **kw): return the_coverage.report(*args, **kw)


# Save coverage data when Python exits.  (The atexit module wasn't
# introduced until Python 2.0, so use sys.exitfunc when it's not
# available.)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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")
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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")
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    sys.exit(0)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)