Python sys.exitfunc() Examples

The following are code examples for showing how to use sys.exitfunc(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: zippy   Author: securesystemslab   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 2
Project: kibtool   Author: jpparis-orange   File: run_tests.py    (license) View Source Project 6 votes vote down vote up
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__))
  ) 
Example 3
Project: pefile.pypy   Author: cloudtracer   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 4
Project: ouroboros   Author: pybee   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 5
Project: kbe_server   Author: xiaohaoppy   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 6
Project: mac-package-build   Author: persepolisdm   File: test_modulegraph_more.py    (license) View Source Project 6 votes vote down vote up
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') 
Example 7
Project: zippy   Author: securesystemslab   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 8
Project: zippy   Author: securesystemslab   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 9
Project: zippy   Author: securesystemslab   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 10
Project: zippy   Author: securesystemslab   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 11
Project: zippy   Author: securesystemslab   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 12
Project: oil   Author: oilshell   File: test_atexit.py    (license) View Source Project 5 votes vote down vote up
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") 
Example 13
Project: oil   Author: oilshell   File: run.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 14
Project: oil   Author: oilshell   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 15
Project: oil   Author: oilshell   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 16
Project: oil   Author: oilshell   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 17
Project: oil   Author: oilshell   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 18
Project: oil   Author: oilshell   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 19
Project: oil   Author: oilshell   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 20
Project: python2-tracer   Author: extremecoders-re   File: test_atexit.py    (license) View Source Project 5 votes vote down vote up
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") 
Example 21
Project: python2-tracer   Author: extremecoders-re   File: run.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 22
Project: python2-tracer   Author: extremecoders-re   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 23
Project: python2-tracer   Author: extremecoders-re   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 24
Project: python2-tracer   Author: extremecoders-re   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 25
Project: python2-tracer   Author: extremecoders-re   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 26
Project: python2-tracer   Author: extremecoders-re   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 27
Project: python2-tracer   Author: extremecoders-re   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 28
Project: isard   Author: isard-vdi   File: events_recolector.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 29
Project: isard   Author: isard-vdi   File: events_recolector.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 30
Project: django-chemtrails   Author: inonit   File: run_tests.py    (license) View Source Project 5 votes vote down vote up
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__))) 
Example 31
Project: django-hesab   Author: rhblind   File: runtests.py    (license) View Source Project 5 votes vote down vote up
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__))) 
Example 32
Project: django-haystack-elasticsearch   Author: CraveFood   File: run_tests.py    (license) View Source Project 5 votes vote down vote up
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__))
    ) 
Example 33
Project: gdata-python3   Author: dvska   File: coverage.py    (license) View Source Project 5 votes vote down vote up
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.) 
Example 34
Project: pefile.pypy   Author: cloudtracer   File: test_atexit.py    (license) View Source Project 5 votes vote down vote up
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") 
Example 35
Project: pefile.pypy   Author: cloudtracer   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 36
Project: pefile.pypy   Author: cloudtracer   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 37
Project: pefile.pypy   Author: cloudtracer   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 38
Project: pefile.pypy   Author: cloudtracer   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 39
Project: pefile.pypy   Author: cloudtracer   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 40
Project: ouroboros   Author: pybee   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 41
Project: ouroboros   Author: pybee   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 42
Project: ouroboros   Author: pybee   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 43
Project: ouroboros   Author: pybee   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 44
Project: ouroboros   Author: pybee   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 45
Project: ndk-python   Author: gittor   File: test_atexit.py    (license) View Source Project 5 votes vote down vote up
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") 
Example 46
Project: ndk-python   Author: gittor   File: run.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 47
Project: kbe_server   Author: xiaohaoppy   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 48
Project: kbe_server   Author: xiaohaoppy   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 49
Project: kbe_server   Author: xiaohaoppy   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 50
Project: kbe_server   Author: xiaohaoppy   File: test_fixers.py    (license) View Source Project 5 votes vote down vote up
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)