1 |
commit: 570faa2a3bd095e4ec86abcf85df3c79a0b418cf |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Aug 8 03:01:35 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Aug 8 03:03:02 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=570faa2a |
7 |
|
8 |
EventLoopInForkTestCase: use AsyncFunction |
9 |
|
10 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
11 |
|
12 |
.../futures/asyncio/test_event_loop_in_fork.py | 23 +++++----------------- |
13 |
1 file changed, 5 insertions(+), 18 deletions(-) |
14 |
|
15 |
diff --git a/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py b/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py |
16 |
index 177953437..e409fd52b 100644 |
17 |
--- a/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py |
18 |
+++ b/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py |
19 |
@@ -1,17 +1,16 @@ |
20 |
-# Copyright 2018 Gentoo Foundation |
21 |
+# Copyright 2018-2020 Gentoo Authors |
22 |
# Distributed under the terms of the GNU General Public License v2 |
23 |
|
24 |
-import multiprocessing |
25 |
import os |
26 |
|
27 |
from portage.tests import TestCase |
28 |
+from portage.util._async.AsyncFunction import AsyncFunction |
29 |
from portage.util._eventloop.global_event_loop import global_event_loop |
30 |
from portage.util.futures import asyncio |
31 |
from portage.util.futures.unix_events import DefaultEventLoopPolicy |
32 |
|
33 |
|
34 |
-def fork_main(parent_conn, child_conn): |
35 |
- parent_conn.close() |
36 |
+def fork_main(): |
37 |
loop = asyncio._wrap_loop() |
38 |
# This fails with python's default event loop policy, |
39 |
# see https://bugs.python.org/issue22087. |
40 |
@@ -21,21 +20,9 @@ def fork_main(parent_conn, child_conn): |
41 |
|
42 |
def async_main(fork_exitcode, loop=None): |
43 |
loop = asyncio._wrap_loop(loop) |
44 |
- |
45 |
- # Since python2.7 does not support Process.sentinel, use Pipe to |
46 |
- # monitor for process exit. |
47 |
- parent_conn, child_conn = multiprocessing.Pipe() |
48 |
- |
49 |
- def eof_callback(proc): |
50 |
- loop.remove_reader(parent_conn.fileno()) |
51 |
- parent_conn.close() |
52 |
- proc.join() |
53 |
- fork_exitcode.set_result(proc.exitcode) |
54 |
- |
55 |
- proc = multiprocessing.Process(target=fork_main, args=(parent_conn, child_conn)) |
56 |
- loop.add_reader(parent_conn.fileno(), eof_callback, proc) |
57 |
+ proc = AsyncFunction(scheduler=loop, target=fork_main) |
58 |
proc.start() |
59 |
- child_conn.close() |
60 |
+ proc.async_wait().add_done_callback(lambda future: fork_exitcode.set_result(future.result())) |
61 |
|
62 |
|
63 |
class EventLoopInForkTestCase(TestCase): |