[Python-Dev] Reaping threads and subprocesses (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Sun Aug 11 20:23:35 CEST 2013
- Previous message: [Python-Dev] Green buildbot failure.
- Next message: [Python-Dev] Dealing with import lock deadlock in Import Hooks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Some tests uses the following idiom:
def test_main(): try: test.support.run_unittest(...) finally: test.support.reap_children()
Other tests uses the following idiom:
def test_main(): key = test.support.threading_setup() try: test.support.run_unittest(...) finally: test.support.threading_cleanup(*key)
or in other words:
@test.support.reap_threads def test_main(): test.support.run_unittest(...)
These tests are not discoverable. There are some ways to make them discoverable.
- Create unittest.TestCase subclasses or mixins with overloaded the run() method.
class ThreadReaped: def run(self, result): key = test.support.threading_setup() try: return super().run(result) finally: test.support.threading_cleanup(*key)
class ChildReaped: def run(self, result): try: return super().run(result) finally: test.support.reap_children()
- Create unittest.TestCase subclasses or mixins with overloaded setUpClass() and tearDownClass() methods.
class ThreadReaped: @classmethod def setUpClass(cls): cls._threads = test.support.threading_setup() @classmethod def tearDownClass(cls): test.support.threading_cleanup(*cls._threads)
class ChildReaped: @classmethod def tearDownClass(cls): test.support.reap_children()
- Create unittest.TestCase subclasses or mixins with overloaded setUp() and tearDown() methods.
class ThreadReaped: def setUp(self): self._threads = test.support.threading_setup() def tearDown(self): test.support.threading_cleanup(*self._threads)
class ChildReaped: def tearDown(self): test.support.reap_children()
- Create unittest.TestCase subclasses or mixins with using addCleanup() in constructor.
class ThreadReaped: def init(self): self.addCleanup(test.support.threading_cleanup, *test.support.threading_setup())
class ChildReaped: def init(self): self.addCleanup(test.support.reap_children)
Of course instead subclassing we can use decorators which modify test class.
What method is better? Do you have other suggestions?
The issue where this problem was first occurred: http://bugs.python.org/issue16968.
- Previous message: [Python-Dev] Green buildbot failure.
- Next message: [Python-Dev] Dealing with import lock deadlock in Import Hooks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]