aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2020-08-07 20:01:35 -0700
committerZac Medico <zmedico@gentoo.org>2020-08-07 20:03:02 -0700
commit570faa2a3bd095e4ec86abcf85df3c79a0b418cf (patch)
tree8b497a342b4e840f303d6cee66aba3116c44630d /lib/portage/tests/util/futures
parentlib/*: Fix useless-return (diff)
downloadportage-570faa2a3bd095e4ec86abcf85df3c79a0b418cf.tar.gz
portage-570faa2a3bd095e4ec86abcf85df3c79a0b418cf.tar.bz2
portage-570faa2a3bd095e4ec86abcf85df3c79a0b418cf.zip
EventLoopInForkTestCase: use AsyncFunction
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib/portage/tests/util/futures')
-rw-r--r--lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py23
1 files 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):