1 |
Make the _safe_loop function return an AsyncioEventLoop instance, |
2 |
so that the default asyncio event loop implementation will be used |
3 |
in API consumer threads. This is possible because the underlying |
4 |
asyncio.get_event_loop() function returns a new event loop for |
5 |
each thread. The AsyncioEventLoop _run_until_complete method will |
6 |
now appropriately handle a ValueError from signal.set_wakeup_fd(-1) |
7 |
if it is not called in the main thread. |
8 |
|
9 |
Bug: https://bugs.gentoo.org/758755 |
10 |
Signed-off-by: Zac Medico <zmedico@g.o> |
11 |
--- |
12 |
[PATCH v3] fixed AsyncioEventLoop _run_until_complete method to |
13 |
handle ValueError from signal.set_wakeup_fd(-1) |
14 |
|
15 |
lib/portage/util/_eventloop/asyncio_event_loop.py | 6 +++++- |
16 |
lib/portage/util/futures/_asyncio/__init__.py | 3 +-- |
17 |
2 files changed, 6 insertions(+), 3 deletions(-) |
18 |
|
19 |
diff --git a/lib/portage/util/_eventloop/asyncio_event_loop.py b/lib/portage/util/_eventloop/asyncio_event_loop.py |
20 |
index 836f1c30a..4d7047ae8 100644 |
21 |
--- a/lib/portage/util/_eventloop/asyncio_event_loop.py |
22 |
+++ b/lib/portage/util/_eventloop/asyncio_event_loop.py |
23 |
@@ -121,4 +121,8 @@ class AsyncioEventLoop(_AbstractEventLoop): |
24 |
try: |
25 |
return self._loop.run_until_complete(future) |
26 |
finally: |
27 |
- self._wakeup_fd = signal.set_wakeup_fd(-1) |
28 |
+ try: |
29 |
+ self._wakeup_fd = signal.set_wakeup_fd(-1) |
30 |
+ except ValueError: |
31 |
+ # This is intended to fail when not called in the main thread. |
32 |
+ pass |
33 |
diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py |
34 |
index a902ad895..12013be00 100644 |
35 |
--- a/lib/portage/util/futures/_asyncio/__init__.py |
36 |
+++ b/lib/portage/util/futures/_asyncio/__init__.py |
37 |
@@ -34,7 +34,6 @@ import portage |
38 |
portage.proxy.lazyimport.lazyimport(globals(), |
39 |
'portage.util.futures.unix_events:_PortageEventLoopPolicy', |
40 |
'portage.util.futures:compat_coroutine@_compat_coroutine', |
41 |
- 'portage.util._eventloop.EventLoop:EventLoop@_EventLoop', |
42 |
) |
43 |
from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop |
44 |
from portage.util._eventloop.global_event_loop import ( |
45 |
@@ -256,4 +255,4 @@ def _safe_loop(): |
46 |
""" |
47 |
if portage._internal_caller: |
48 |
return _global_event_loop() |
49 |
- return _EventLoop(main=False) |
50 |
+ return _AsyncioEventLoop() |
51 |
-- |
52 |
2.26.2 |