From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:prefix commit in: lib/portage/
Date: Mon, 4 Jan 2021 10:42:32 +0000 (UTC) [thread overview]
Message-ID: <1609756914.c7198b5b3eb17e8b20930dc83b3a210f09802a1d.grobian@gentoo> (raw)
commit: c7198b5b3eb17e8b20930dc83b3a210f09802a1d
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 4 04:59:49 2020 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Jan 4 10:41:54 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c7198b5b
_get_lock_fn: support multiprocessing spawn start method (bug 758230)
Ensure that _get_lock_fn arguments to multiprocessing.Process will
successfully pickle, as required by the spawn start method, which
is the default for macOS since Python 3.8.
Since file descriptors are not inherited unless the fork start
method is used, the subprocess should only try to close an
inherited file descriptor for the fork start method.
Bug: https://bugs.gentoo.org/758230
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
lib/portage/locks.py | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/lib/portage/locks.py b/lib/portage/locks.py
index 1073343be..193045c03 100644
--- a/lib/portage/locks.py
+++ b/lib/portage/locks.py
@@ -44,18 +44,7 @@ def _get_lock_fn():
if _lock_fn is not None:
return _lock_fn
- def _test_lock(fd, lock_path):
- os.close(fd)
- try:
- with open(lock_path, 'a') as f:
- fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
- except EnvironmentError as e:
- if e.errno == errno.EAGAIN:
- # Parent process holds lock, as expected.
- sys.exit(0)
- # Something went wrong.
- sys.exit(1)
fd, lock_path = tempfile.mkstemp()
try:
@@ -64,8 +53,16 @@ def _get_lock_fn():
except EnvironmentError:
pass
else:
- proc = multiprocessing.Process(target=_test_lock,
- args=(fd, lock_path))
+ proc = multiprocessing.Process(
+ target=_subprocess_test_lock,
+ args=(
+ # Since file descriptors are not inherited unless the fork start
+ # method is used, the subprocess should only try to close an
+ # inherited file descriptor for the fork start method.
+ fd if multiprocessing.get_start_method() == "fork" else None,
+ lock_path,
+ ),
+ )
proc.start()
proc.join()
if proc.exitcode == os.EX_OK:
@@ -80,6 +77,19 @@ def _get_lock_fn():
_lock_fn = fcntl.flock
return _lock_fn
+def _subprocess_test_lock(fd, lock_path):
+ if fd is not None:
+ os.close(fd)
+ try:
+ with open(lock_path, 'a') as f:
+ fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
+ except EnvironmentError as e:
+ if e.errno == errno.EAGAIN:
+ # Parent process holds lock, as expected.
+ sys.exit(0)
+
+ # Something went wrong.
+ sys.exit(1)
_open_fds = {}
_open_inodes = {}
next reply other threads:[~2021-01-04 10:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-04 10:42 Fabian Groffen [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-01-18 11:51 [gentoo-commits] proj/portage:prefix commit in: lib/portage/ Fabian Groffen
2023-11-25 19:08 Fabian Groffen
2023-11-24 20:06 Fabian Groffen
2022-07-24 9:45 Fabian Groffen
2021-01-04 12:07 Fabian Groffen
2019-07-01 13:11 Fabian Groffen
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=1609756914.c7198b5b3eb17e8b20930dc83b3a210f09802a1d.grobian@gentoo \
--to=grobian@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