summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_subprocess.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2019-06-30 09:54:59 (GMT)
committerGitHub <noreply@github.com>2019-06-30 09:54:59 (GMT)
commit0d671c04c39b52e44597491b893eb0b6c86b3d45 (patch)
treeb48295515be5ed2aed7babe62a924266edfdde6a /Lib/test/test_asyncio/test_subprocess.py
parent5cbbbd73a6acb6f96f5d6646aa7498d3dfb1706d (diff)
downloadcpython-0d671c04c39b52e44597491b893eb0b6c86b3d45.zip
cpython-0d671c04c39b52e44597491b893eb0b6c86b3d45.tar.gz
cpython-0d671c04c39b52e44597491b893eb0b6c86b3d45.tar.bz2
bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread (GH-14344)
Diffstat (limited to 'Lib/test/test_asyncio/test_subprocess.py')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index e9a9e50..b9578b2 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -633,6 +633,7 @@ class SubprocessMixin:
self.assertIsNone(self.loop.run_until_complete(execute()))
+
if sys.platform != 'win32':
# Unix
class SubprocessWatcherMixin(SubprocessMixin):
@@ -648,7 +649,24 @@ if sys.platform != 'win32':
watcher = self.Watcher()
watcher.attach_loop(self.loop)
policy.set_child_watcher(watcher)
- self.addCleanup(policy.set_child_watcher, None)
+
+ def tearDown(self):
+ super().tearDown()
+ policy = asyncio.get_event_loop_policy()
+ watcher = policy.get_child_watcher()
+ policy.set_child_watcher(None)
+ watcher.attach_loop(None)
+ watcher.close()
+
+ class SubprocessThreadedWatcherTests(SubprocessWatcherMixin,
+ test_utils.TestCase):
+
+ Watcher = unix_events.ThreadedChildWatcher
+
+ class SubprocessMultiLoopWatcherTests(SubprocessWatcherMixin,
+ test_utils.TestCase):
+
+ Watcher = unix_events.MultiLoopChildWatcher
class SubprocessSafeWatcherTests(SubprocessWatcherMixin,
test_utils.TestCase):
@@ -670,5 +688,25 @@ else:
self.set_event_loop(self.loop)
+class GenericWatcherTests:
+
+ def test_create_subprocess_fails_with_inactive_watcher(self):
+
+ async def execute():
+ watcher = mock.create_authspec(asyncio.AbstractChildWatcher)
+ watcher.is_active.return_value = False
+ asyncio.set_child_watcher(watcher)
+
+ with self.assertRaises(RuntimeError):
+ await subprocess.create_subprocess_exec(
+ support.FakePath(sys.executable), '-c', 'pass')
+
+ watcher.add_child_handler.assert_not_called()
+
+ self.assertIsNone(self.loop.run_until_complete(execute()))
+
+
+
+
if __name__ == '__main__':
unittest.main()