Skip to content

Commit af9cda9

Browse files
authored
Revert "bpo-22087: Fix Policy.get_event_loop() to detect fork (GH-7208)" (GH-7233)
This reverts commit 2a7eb0b.
1 parent 3ddee64 commit af9cda9

File tree

3 files changed

+0
-42
lines changed

3 files changed

+0
-42
lines changed

Lib/asyncio/events.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,23 +625,16 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
625625

626626
class _Local(threading.local):
627627
_loop = None
628-
_pid = None
629628
_set_called = False
630629

631630
def __init__(self):
632631
self._local = self._Local()
633-
self._local._pid = os.getpid()
634632

635633
def get_event_loop(self):
636634
"""Get the event loop.
637635
638636
This may be None or an instance of EventLoop.
639637
"""
640-
if self._local._pid != os.getpid():
641-
# If we detect we're in a child process forked by multiprocessing,
642-
# we reset self._local so that we'll get a new event loop.
643-
self._local = self._Local()
644-
645638
if (self._local._loop is None and
646639
not self._local._set_called and
647640
isinstance(threading.current_thread(), threading._MainThread)):

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import tempfile
1414
import threading
1515
import unittest
16-
import multiprocessing
1716
from unittest import mock
1817
from test import support
1918

@@ -1793,37 +1792,6 @@ def create_watcher(self):
17931792
return asyncio.FastChildWatcher()
17941793

17951794

1796-
class ForkedProcessTests(unittest.TestCase):
1797-
def setUp(self):
1798-
self.parent_loop = asyncio.SelectorEventLoop()
1799-
asyncio.set_event_loop(self.parent_loop)
1800-
self.ctx = multiprocessing.get_context("fork")
1801-
1802-
def tearDown(self):
1803-
self.parent_loop.close()
1804-
1805-
def _check_loops_not_equal(self, old_loop):
1806-
loop = asyncio.get_event_loop()
1807-
if loop is old_loop:
1808-
raise RuntimeError("Child process inherited parent's event loop")
1809-
1810-
try:
1811-
val = loop.run_until_complete(asyncio.sleep(0.05, result=42))
1812-
if val != 42:
1813-
raise RuntimeError("new event loop does not work")
1814-
finally:
1815-
loop.close()
1816-
1817-
sys.exit(loop is old_loop)
1818-
1819-
def test_new_loop_in_child(self):
1820-
p = self.ctx.Process(target=self._check_loops_not_equal,
1821-
args=(self.parent_loop,))
1822-
p.start()
1823-
p.join()
1824-
self.assertEqual(p.exitcode, 0)
1825-
1826-
18271795
class PolicyTests(unittest.TestCase):
18281796

18291797
def create_policy(self):

Misc/NEWS.d/next/Library/2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)