public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/_async/
Date: Tue,  3 Oct 2023 14:48:39 +0000 (UTC)	[thread overview]
Message-ID: <1696344481.04184a03b74669fdb48403cb8002de6395cf8684.zmedico@gentoo> (raw)

commit:     04184a03b74669fdb48403cb8002de6395cf8684
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct  3 07:33:29 2023 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Oct  3 14:48:01 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=04184a03

AsyncFunction: Migrate to ForkProcess target parameter

Bug: https://bugs.gentoo.org/915099
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/util/_async/AsyncFunction.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/portage/util/_async/AsyncFunction.py b/lib/portage/util/_async/AsyncFunction.py
index f27b255a55..e13daaebb0 100644
--- a/lib/portage/util/_async/AsyncFunction.py
+++ b/lib/portage/util/_async/AsyncFunction.py
@@ -1,6 +1,7 @@
 # Copyright 2015-2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import functools
 import pickle
 import traceback
 
@@ -19,26 +20,27 @@ class AsyncFunction(ForkProcess):
     __slots__ = (
         "result",
         "_async_func_reader",
-        "_async_func_reader_pw",
     )
 
     def _start(self):
         pr, pw = os.pipe()
         self.fd_pipes = {} if self.fd_pipes is None else self.fd_pipes
         self.fd_pipes[pw] = pw
-        self._async_func_reader_pw = pw
         self._async_func_reader = PipeReader(
             input_files={"input": pr}, scheduler=self.scheduler
         )
         self._async_func_reader.addExitListener(self._async_func_reader_exit)
         self._async_func_reader.start()
+        # args and kwargs are passed as additional args by ForkProcess._bootstrap.
+        self.target = functools.partial(self._target_wrapper, pw, self.target)
         ForkProcess._start(self)
         os.close(pw)
 
-    def _run(self):
+    @staticmethod
+    def _target_wrapper(pw, target, *args, **kwargs):
         try:
-            result = self.target(*(self.args or []), **(self.kwargs or {}))
-            os.write(self._async_func_reader_pw, pickle.dumps(result))
+            result = target(*args, **kwargs)
+            os.write(pw, pickle.dumps(result))
         except Exception:
             traceback.print_exc()
             return 1


             reply	other threads:[~2023-10-03 14:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03 14:48 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-02-14 15:45 [gentoo-commits] proj/portage:master commit in: lib/portage/util/_async/ Zac Medico
2024-02-07  2:35 Zac Medico
2024-02-03 22:54 Zac Medico
2023-12-06 16:25 Zac Medico
2023-10-05  6:28 Zac Medico
2023-10-04  4:01 Zac Medico
2023-10-04  3:25 Zac Medico
2023-10-03 14:48 Zac Medico
2021-09-21  5:51 Zac Medico
2021-05-02  0:00 Zac Medico
2021-03-07 15:17 Zac Medico
2021-03-07 15:17 Zac Medico
2021-02-15  4:38 Zac Medico
2020-08-09  0:46 Zac Medico
2020-08-03 23:28 Zac Medico
2020-06-24  4:36 Zac Medico
2020-06-14  0:02 Zac Medico
2020-04-08  5:56 Zac Medico
2020-03-01  1:22 Zac Medico
2020-02-29  7:51 Zac Medico
2020-02-29  7:51 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1696344481.04184a03b74669fdb48403cb8002de6395cf8684.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox