Python atexit._clear() Examples

The following are code examples for showing how to use atexit._clear(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: pyzy   Author: msolo   File: pyzy_server.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _fix_child_modules():
  # Remove any exit handlers - anything registered at this point is not
  # relevant.
  if sys.version_info.major == 2:
    del atexit._exithandlers[:]
  else:
    atexit._clear()

  # # the logging module is fun too - it has locks that might be held by a
  # # thread in the parent process. to prevent intermittent deadlock, you need
  # # to reset the locks. this just feels dirty.
  # logging._lock = None
  # logging._acquireLock()
  # for handler in logging._handlers:
  #   # this will overwrite the individual locks on each handler
  #   handler.createLock()
  # logging._releaseLock()

  # Make sure each process has a different random seed.
  random.seed() 
Example 2
Project: NiujiaoDebugger   Author: MrSrc   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        self.stream = io.StringIO()
        sys.stdout = sys.stderr = self.stream
        atexit._clear() 
Example 3
Project: NiujiaoDebugger   Author: MrSrc   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        sys.stdout = self.save_stdout
        sys.stderr = self.save_stderr
        atexit._clear() 
Example 4
Project: NiujiaoDebugger   Author: MrSrc   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def test_clear(self):
        a = [0]
        def inc():
            a[0] += 1

        atexit.register(inc)
        atexit._clear()
        atexit._run_exitfuncs()

        self.assertEqual(a[0], 0) 
Example 5
Project: NiujiaoDebugger   Author: MrSrc   File: run.py    GNU General Public License v3.0 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first clearing exit functions.

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

    """
    if no_exitfunc:
        import atexit
        atexit._clear()
    capture_warnings(False)
    sys.exit(0) 
Example 6
Project: locust-plugins   Author: SvenskaSpel   File: listeners.py    Apache License 2.0 5 votes vote down vote up
def quitting(self):
        self._finished = True
        atexit._clear()  # make sure we dont capture additional ctrl-c:s # pylint: disable=protected-access
        self._background.join()
        if not is_slave():
            self._user_count_logger.kill()
        self.exit() 
Example 7
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        self.stream = io.StringIO()
        sys.stdout = sys.stderr = self.stream
        atexit._clear() 
Example 8
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        sys.stdout = self.save_stdout
        sys.stderr = self.save_stderr
        atexit._clear() 
Example 9
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def test_clear(self):
        a = [0]
        def inc():
            a[0] += 1

        atexit.register(inc)
        atexit._clear()
        atexit._run_exitfuncs()

        self.assertEqual(a[0], 0) 
Example 10
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_atexit.py    GNU General Public License v2.0 5 votes vote down vote up
def setUp(self):
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        self.stream = io.StringIO()
        sys.stdout = sys.stderr = self.stream
        atexit._clear() 
Example 11
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_atexit.py    GNU General Public License v2.0 5 votes vote down vote up
def tearDown(self):
        sys.stdout = self.save_stdout
        sys.stderr = self.save_stderr
        atexit._clear() 
Example 12
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_atexit.py    GNU General Public License v2.0 5 votes vote down vote up
def test_clear(self):
        a = [0]
        def inc():
            a[0] += 1

        atexit.register(inc)
        atexit._clear()
        atexit._run_exitfuncs()

        self.assertEqual(a[0], 0) 
Example 13
Project: aws-lambda-runtime-pypy   Author: uscheller   File: run.py    Apache License 2.0 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first clearing exit functions.

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

    """
    if no_exitfunc:
        import atexit
        atexit._clear()
    capture_warnings(False)
    sys.exit(0) 
Example 14
Project: pysumo   Author: pySUMO   File: syntaxcontroller.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def tearDown(self):
        atexit._clear()
        self.sumo.action_log.log_io.flush_write_queues()
        self.milo.action_log.log_io.flush_write_queues()
        rmtree(self.tmpdir) 
Example 15
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        self.stream = io.StringIO()
        sys.stdout = sys.stderr = self.stream
        atexit._clear() 
Example 16
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        sys.stdout = self.save_stdout
        sys.stderr = self.save_stderr
        atexit._clear() 
Example 17
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_atexit.py    GNU General Public License v3.0 5 votes vote down vote up
def test_clear(self):
        a = [0]
        def inc():
            a[0] += 1

        atexit.register(inc)
        atexit._clear()
        atexit._run_exitfuncs()

        self.assertEqual(a[0], 0) 
Example 18
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: run.py    GNU General Public License v3.0 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first clearing exit functions.

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

    """
    if no_exitfunc:
        import atexit
        atexit._clear()
    capture_warnings(False)
    sys.exit(0) 
Example 19
Project: cells   Author: AlesTsurko   File: test_atexit.py    MIT License 5 votes vote down vote up
def setUp(self):
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        self.stream = io.StringIO()
        sys.stdout = sys.stderr = self.stream
        atexit._clear() 
Example 20
Project: cells   Author: AlesTsurko   File: test_atexit.py    MIT License 5 votes vote down vote up
def tearDown(self):
        sys.stdout = self.save_stdout
        sys.stderr = self.save_stderr
        atexit._clear() 
Example 21
Project: cells   Author: AlesTsurko   File: test_atexit.py    MIT License 5 votes vote down vote up
def test_clear(self):
        a = [0]
        def inc():
            a[0] += 1

        atexit.register(inc)
        atexit._clear()
        atexit._run_exitfuncs()

        self.assertEqual(a[0], 0) 
Example 22
Project: cells   Author: AlesTsurko   File: run.py    MIT License 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first clearing exit functions.

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

    """
    if no_exitfunc:
        import atexit
        atexit._clear()
    capture_warnings(False)
    sys.exit(0)