Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/
Date: Mon, 08 Feb 2021 04:55:37
Message-Id: 1612759640.ef43dd8ef64ded5f0627b7b8e84ef21262012902.zmedico@gentoo
1 commit: ef43dd8ef64ded5f0627b7b8e84ef21262012902
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jan 30 12:44:19 2021 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Mon Feb 8 04:47:20 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ef43dd8e
7
8 portage.getpid: call os.getpid() lazily
9
10 Call os.getpid() lazily, which eliminates getpid calls when possible
11 after os.fork() in the portage.process module.
12
13 Bug: https://bugs.gentoo.org/767913
14 Reviewed-by: Brian Dolbec <dolsen <AT> gentoo.org>
15 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
16
17 lib/portage/__init__.py | 4 +++-
18 1 file changed, 3 insertions(+), 1 deletion(-)
19
20 diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py
21 index 3c9f78497..24c9d8b89 100644
22 --- a/lib/portage/__init__.py
23 +++ b/lib/portage/__init__.py
24 @@ -375,7 +375,7 @@ _sync_mode = False
25 class _ForkWatcher:
26 @staticmethod
27 def hook(_ForkWatcher):
28 - _ForkWatcher.current_pid = _os.getpid()
29 + _ForkWatcher.current_pid = None
30 # Force instantiation of a new event loop policy as a workaround
31 # for https://bugs.python.org/issue22087.
32 asyncio.set_event_loop_policy(None)
33 @@ -388,6 +388,8 @@ def getpid():
34 """
35 Cached version of os.getpid(). ForkProcess updates the cache.
36 """
37 + if _ForkWatcher.current_pid is None:
38 + _ForkWatcher.current_pid = _os.getpid()
39 return _ForkWatcher.current_pid
40
41 def _get_stdin():