diff options
author | Yury Selivanov <yury@magic.io> | 2018-05-29 19:38:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-29 19:38:07 (GMT) |
commit | 5d97b7bcc19496617bf8c448d2f149cc28c73bc7 (patch) | |
tree | 3a8393d343de0c3a54040eaf380cc8b19eb1577d /Lib/asyncio | |
parent | e55de2d77f10d524be0b426e587fbc820f76de71 (diff) | |
download | cpython-5d97b7bcc19496617bf8c448d2f149cc28c73bc7.zip cpython-5d97b7bcc19496617bf8c448d2f149cc28c73bc7.tar.gz cpython-5d97b7bcc19496617bf8c448d2f149cc28c73bc7.tar.bz2 |
bpo-22087: Fix Policy.get_event_loop() to detect fork (GH-7208)
Original patch by Dan O'Reilly.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/events.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index 40946bb..68dc25e 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -625,16 +625,23 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy): class _Local(threading.local): _loop = None + _pid = None _set_called = False def __init__(self): self._local = self._Local() + self._local._pid = os.getpid() def get_event_loop(self): """Get the event loop. This may be None or an instance of EventLoop. """ + if self._local._pid != os.getpid(): + # If we detect we're in a child process forked by multiprocessing, + # we reset self._local so that we'll get a new event loop. + self._local = self._Local() + if (self._local._loop is None and not self._local._set_called and isinstance(threading.current_thread(), threading._MainThread)): |