From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 159FB158089 for ; Thu, 2 Nov 2023 14:57:22 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 54A1A2BC013; Thu, 2 Nov 2023 14:57:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3B8422BC013 for ; Thu, 2 Nov 2023 14:57:21 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 38352335CCD for ; Thu, 2 Nov 2023 14:57:20 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 967AAAA6 for ; Thu, 2 Nov 2023 14:57:18 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1698936997.3b1234ba69a31709cd5aec1ae070901e3a28bb7c.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/tests/process/test_AsyncFunction.py X-VCS-Directories: lib/portage/tests/process/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 3b1234ba69a31709cd5aec1ae070901e3a28bb7c X-VCS-Branch: master Date: Thu, 2 Nov 2023 14:57:18 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 388b6a70-770b-4dcf-8baf-2d0a23d2262b X-Archives-Hash: f864e6c77cf84ff71b30da7fd27814ff commit: 3b1234ba69a31709cd5aec1ae070901e3a28bb7c Author: Zac Medico gentoo org> AuthorDate: Wed Nov 1 05:07:32 2023 +0000 Commit: Zac Medico gentoo org> CommitDate: Thu Nov 2 14:56:37 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3b1234ba testAsyncFunctionStdin: multiprocessing spawn compat For compatibility with the multiprocessing spawn start method, we delay restoration of the stdin file descriptor, since this file descriptor is sent to the subprocess asynchronously. Signed-off-by: Zac Medico gentoo.org> Bug: https://bugs.gentoo.org/916601 lib/portage/tests/process/test_AsyncFunction.py | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/portage/tests/process/test_AsyncFunction.py b/lib/portage/tests/process/test_AsyncFunction.py index d02a3395c1..1faf8f49f7 100644 --- a/lib/portage/tests/process/test_AsyncFunction.py +++ b/lib/portage/tests/process/test_AsyncFunction.py @@ -42,21 +42,37 @@ class AsyncFunctionTestCase(TestCase): ), ) reader.start() + # For compatibility with the multiprocessing spawn start + # method, we delay restoration of the stdin file descriptor, + # since this file descriptor is sent to the subprocess + # asynchronously. + _set_nonblocking(pw.fileno()) + with open(pw.fileno(), mode="wb", buffering=0, closefd=False) as pipe_write: + await _writer(pipe_write, test_string.encode("utf_8")) + pw.close() + self.assertEqual((await reader.async_wait()), os.EX_OK) + self.assertEqual(reader.result, test_string) finally: os.dup2(stdin_backup, portage._get_stdin().fileno()) os.close(stdin_backup) - _set_nonblocking(pw.fileno()) - with open(pw.fileno(), mode="wb", buffering=0, closefd=False) as pipe_write: - await _writer(pipe_write, test_string.encode("utf_8")) - pw.close() - self.assertEqual((await reader.async_wait()), os.EX_OK) - self.assertEqual(reader.result, test_string) - def testAsyncFunctionStdin(self): loop = asyncio._wrap_loop() loop.run_until_complete(self._testAsyncFunctionStdin(loop=loop)) + def testAsyncFunctionStdinSpawn(self): + orig_start_method = multiprocessing.get_start_method() + if orig_start_method == "spawn": + self.skipTest("multiprocessing start method is already spawn") + # NOTE: An attempt was made to use multiprocessing.get_context("spawn") + # here, but it caused the python process to terminate unexpectedly + # during a send_handle call. + multiprocessing.set_start_method("spawn", force=True) + try: + self.testAsyncFunctionStdin() + finally: + multiprocessing.set_start_method(orig_start_method, force=True) + @staticmethod def _test_getpid_fork(preexec_fn=None): """