[Python-checkins] Revert "bpo-22087: Fix Policy.get_event_loop() to detect fork (GH-7208)" (GH-7233)

Yury Selivanov webhook-mailer at python.org
Tue May 29 20:56:36 EDT 2018


https://github.com/python/cpython/commit/af9cda9845666e2f704177a431d29f91efbf828a
commit: af9cda9845666e2f704177a431d29f91efbf828a
branch: 3.7
author: Yury Selivanov <yury at magic.io>
committer: GitHub <noreply at github.com>
date: 2018-05-29T20:56:33-04:00
summary:

Revert "bpo-22087: Fix Policy.get_event_loop() to detect fork (GH-7208)" (GH-7233)

This reverts commit 2a7eb0b531656f4a77d85078e6e009e4b3639ef9.

files:
D Misc/NEWS.d/next/Library/2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst
M Lib/asyncio/events.py
M Lib/test/test_asyncio/test_unix_events.py

diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 68dc25e1e8be..40946bbf6529 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -625,23 +625,16 @@ 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)):
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 577566851223..104f99593797 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -13,7 +13,6 @@
 import tempfile
 import threading
 import unittest
-import multiprocessing
 from unittest import mock
 from test import support
 
@@ -1793,37 +1792,6 @@ def create_watcher(self):
         return asyncio.FastChildWatcher()
 
 
-class ForkedProcessTests(unittest.TestCase):
-    def setUp(self):
-        self.parent_loop = asyncio.SelectorEventLoop()
-        asyncio.set_event_loop(self.parent_loop)
-        self.ctx = multiprocessing.get_context("fork")
-
-    def tearDown(self):
-        self.parent_loop.close()
-
-    def _check_loops_not_equal(self, old_loop):
-        loop = asyncio.get_event_loop()
-        if loop is old_loop:
-            raise RuntimeError("Child process inherited parent's event loop")
-
-        try:
-            val = loop.run_until_complete(asyncio.sleep(0.05, result=42))
-            if val != 42:
-                raise RuntimeError("new event loop does not work")
-        finally:
-            loop.close()
-
-        sys.exit(loop is old_loop)
-
-    def test_new_loop_in_child(self):
-        p = self.ctx.Process(target=self._check_loops_not_equal,
-                             args=(self.parent_loop,))
-        p.start()
-        p.join()
-        self.assertEqual(p.exitcode, 0)
-
-
 class PolicyTests(unittest.TestCase):
 
     def create_policy(self):
diff --git a/Misc/NEWS.d/next/Library/2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst b/Misc/NEWS.d/next/Library/2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst
deleted file mode 100644
index 92127cd57a91..000000000000
--- a/Misc/NEWS.d/next/Library/2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst
+++ /dev/null
@@ -1,3 +0,0 @@
-Fix Policy.get_event_loop() to detect fork and return a new loop.
-
-Original patch by Dan O'Reilly.



More information about the Python-checkins mailing list