1 |
Use the default asyncio event loop implementation in child |
2 |
processes, instead of portage's internal EventLoop. After |
3 |
fork, instantiate a new asyncio.DefaultEventLoopPolicy as |
4 |
a workaround for https://bugs.python.org/issue22087, which |
5 |
is necessary for RetryTestCase to succeed. |
6 |
|
7 |
Bug: https://bugs.gentoo.org/758740 |
8 |
Signed-off-by: Zac Medico <zmedico@g.o> |
9 |
--- |
10 |
lib/portage/__init__.py | 4 ++++ |
11 |
lib/portage/util/_eventloop/global_event_loop.py | 7 ------- |
12 |
2 files changed, 4 insertions(+), 7 deletions(-) |
13 |
|
14 |
diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py |
15 |
index 4d4b590a8..2b821e81a 100644 |
16 |
--- a/lib/portage/__init__.py |
17 |
+++ b/lib/portage/__init__.py |
18 |
@@ -9,6 +9,7 @@ VERSION = "HEAD" |
19 |
# =========================================================================== |
20 |
|
21 |
try: |
22 |
+ import asyncio |
23 |
import sys |
24 |
import errno |
25 |
if not hasattr(errno, 'ESTALE'): |
26 |
@@ -373,6 +374,9 @@ class _ForkWatcher: |
27 |
@staticmethod |
28 |
def hook(_ForkWatcher): |
29 |
_ForkWatcher.current_pid = _os.getpid() |
30 |
+ # Force instantiation of a new event loop as a workaround for |
31 |
+ # https://bugs.python.org/issue22087. |
32 |
+ asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy()) |
33 |
|
34 |
_ForkWatcher.hook(_ForkWatcher) |
35 |
|
36 |
diff --git a/lib/portage/util/_eventloop/global_event_loop.py b/lib/portage/util/_eventloop/global_event_loop.py |
37 |
index 21a1d1970..413011178 100644 |
38 |
--- a/lib/portage/util/_eventloop/global_event_loop.py |
39 |
+++ b/lib/portage/util/_eventloop/global_event_loop.py |
40 |
@@ -2,11 +2,8 @@ |
41 |
# Distributed under the terms of the GNU General Public License v2 |
42 |
|
43 |
import portage |
44 |
-from .EventLoop import EventLoop |
45 |
from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop |
46 |
|
47 |
- |
48 |
-_MAIN_PID = portage.getpid() |
49 |
_instances = {} |
50 |
|
51 |
|
52 |
@@ -22,10 +19,6 @@ def global_event_loop(): |
53 |
return instance |
54 |
|
55 |
constructor = AsyncioEventLoop |
56 |
- # If the default constructor doesn't support multiprocessing, |
57 |
- # then multiprocessing constructor is used in subprocesses. |
58 |
- if not constructor.supports_multiprocessing and pid != _MAIN_PID: |
59 |
- constructor = EventLoop |
60 |
|
61 |
# Use the _asyncio_wrapper attribute, so that unit tests can compare |
62 |
# the reference to one retured from _wrap_loop(), since they should |
63 |
-- |
64 |
2.26.2 |