commit:     570faa2a3bd095e4ec86abcf85df3c79a0b418cf
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Aug  8 03:01:35 2020 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Aug  8 03:03:02 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=570faa2a

EventLoopInForkTestCase: use AsyncFunction

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 .../futures/asyncio/test_event_loop_in_fork.py     | 23 +++++-----------------
 1 file changed, 5 insertions(+), 18 deletions(-)

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
index 177953437..e409fd52b 100644
--- 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
@@ -1,17 +1,16 @@
-# Copyright 2018 Gentoo Foundation
+# Copyright 2018-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
-import multiprocessing
 import os
 
 from portage.tests import TestCase
+from portage.util._async.AsyncFunction import AsyncFunction
 from portage.util._eventloop.global_event_loop import global_event_loop
 from portage.util.futures import asyncio
 from portage.util.futures.unix_events import DefaultEventLoopPolicy
 
 
-def fork_main(parent_conn, child_conn):
-       parent_conn.close()
+def fork_main():
        loop = asyncio._wrap_loop()
        # This fails with python's default event loop policy,
        # see https://bugs.python.org/issue22087.
@@ -21,21 +20,9 @@ def fork_main(parent_conn, child_conn):
 
 def async_main(fork_exitcode, loop=None):
        loop = asyncio._wrap_loop(loop)
-
-       # Since python2.7 does not support Process.sentinel, use Pipe to
-       # monitor for process exit.
-       parent_conn, child_conn = multiprocessing.Pipe()
-
-       def eof_callback(proc):
-               loop.remove_reader(parent_conn.fileno())
-               parent_conn.close()
-               proc.join()
-               fork_exitcode.set_result(proc.exitcode)
-
-       proc = multiprocessing.Process(target=fork_main, args=(parent_conn, 
child_conn))
-       loop.add_reader(parent_conn.fileno(), eof_callback, proc)
+       proc = AsyncFunction(scheduler=loop, target=fork_main)
        proc.start()
-       child_conn.close()
+       proc.async_wait().add_done_callback(lambda future: 
fork_exitcode.set_result(future.result()))
 
 
 class EventLoopInForkTestCase(TestCase):

Reply via email to