public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Brian Dolbec <dolsen@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH] portage.getpid: call os.getpid() lazily
Date: Sat, 30 Jan 2021 11:12:24 -0500	[thread overview]
Message-ID: <20210130111224.0b35a69a@rogue1> (raw)
In-Reply-To: <20210130125932.369681-1-zmedico@gentoo.org>

On Sat, 30 Jan 2021 04:59:32 -0800
Zac Medico <zmedico@gentoo.org> wrote:

> Call os.getpid() lazily, which eliminates getpid calls when possible
> after os.fork() in the portage.process module.
> 
> Bug: https://bugs.gentoo.org/767913
> Signed-off-by: Zac Medico <zmedico@gentoo.org>
> ---
>  lib/portage/__init__.py | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py
> index 3c9f78497..24c9d8b89 100644
> --- a/lib/portage/__init__.py
> +++ b/lib/portage/__init__.py
> @@ -375,7 +375,7 @@ _sync_mode = False
>  class _ForkWatcher:
>  	@staticmethod
>  	def hook(_ForkWatcher):
> -		_ForkWatcher.current_pid = _os.getpid()
> +		_ForkWatcher.current_pid = None
>  		# Force instantiation of a new event loop policy as
> a workaround # for https://bugs.python.org/issue22087.
>  		asyncio.set_event_loop_policy(None)
> @@ -388,6 +388,8 @@ def getpid():
>  	"""
>  	Cached version of os.getpid(). ForkProcess updates the cache.
>  	"""
> +	if _ForkWatcher.current_pid is None:
> +		_ForkWatcher.current_pid = _os.getpid()
>  	return _ForkWatcher.current_pid
>  
>  def _get_stdin():

looks good


      reply	other threads:[~2021-01-30 16:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-30 12:59 [gentoo-portage-dev] [PATCH] portage.getpid: call os.getpid() lazily Zac Medico
2021-01-30 16:12 ` Brian Dolbec [this message]

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=20210130111224.0b35a69a@rogue1 \
    --to=dolsen@gentoo.org \
    --cc=gentoo-portage-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