diff options
author | Yury Selivanov <yselivanov@gmail.com> | 2017-03-03 03:06:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-03 03:06:15 (GMT) |
commit | 01e5230ef0b28658cf7311be199363eda98808bd (patch) | |
tree | d794fb36ed44e62c43429353c9a76d64c956779e /Lib/test | |
parent | a6e84933d204f807e0e81b6a2237193b2e8ab89a (diff) | |
download | cpython-01e5230ef0b28658cf7311be199363eda98808bd.zip cpython-01e5230ef0b28658cf7311be199363eda98808bd.tar.gz cpython-01e5230ef0b28658cf7311be199363eda98808bd.tar.bz2 |
bpo-29703: asyncio: Fix creating new event loops in child processes. (#404) (#410)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index 28d92a9..802763b 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -1,6 +1,7 @@ """Tests for events.py.""" import collections.abc +import concurrent.futures import functools import gc import io @@ -57,6 +58,15 @@ def osx_tiger(): return version < (10, 5) +def _test_get_event_loop_new_process__sub_proc(): + async def doit(): + return 'hello' + + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + return loop.run_until_complete(doit()) + + ONLYCERT = data_file('ssl_cert.pem') ONLYKEY = data_file('ssl_key.pem') SIGNED_CERTFILE = data_file('keycert3.pem') @@ -2181,6 +2191,18 @@ else: asyncio.set_child_watcher(None) super().tearDown() + def test_get_event_loop_new_process(self): + async def main(): + pool = concurrent.futures.ProcessPoolExecutor() + return await self.loop.run_in_executor( + pool, _test_get_event_loop_new_process__sub_proc) + + self.unpatch_get_running_loop() + + self.assertEqual( + self.loop.run_until_complete(main()), + 'hello') + if hasattr(selectors, 'KqueueSelector'): class KqueueEventLoopTests(UnixEventLoopTestsMixin, SubprocessTestsMixin, |