Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 739580

Summary: sys-apps/portage: reload of portage module triggers leak in multiprocessing.util._afterfork_registry
Product: Portage Development Reporter: Zac Medico <zmedico>
Component: CoreAssignee: Portage team <dev-portage>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
Package list:
Runtime testing required: ---

Description Zac Medico gentoo-dev 2020-08-30 00:01:18 UTC
Since _ForkWatcher.hook references _ForkWatcher via a staticmethod decorator, it prevents garbage collection of _ForkWatcher when the portage module is reloaded:

> Python 3.8.3 (default, Jul  6 2020, 20:21:42) 
> [GCC 9.2.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import portage
> >>> import multiprocessing.util
> >>> list(multiprocessing.util._afterfork_registry)
> [(0, 94809952799472, <function _ForkWatcher.hook at 0x7f055034b550>)]
> >>> from importlib import reload
> >>> reload(portage)
> <module 'portage' from '/usr/lib/python3.8/site-packages/portage/__init__.py'>
> >>> list(multiprocessing.util._afterfork_registry)
> [(0, 94809952799472, <function _ForkWatcher.hook at 0x7f055034b550>), (1, 94809952837968, <function _ForkWatcher.hook at 0x7f055024f8b0>)]
Comment 1 Zac Medico gentoo-dev 2020-08-30 00:05:10 UTC
Actually, it's not a problem, because gc.collect() really does delete the old _ForkWatcher.