[New-bugs-announce] [issue18674] Store weak references in modules_by_index

Antoine Pitrou report at bugs.python.org
Tue Aug 6 22:38:51 CEST 2013

New submission from Antoine Pitrou:

modules_by_index is a near-eternal store for extension modules. It is only collected at the end of interpreter shutdown, which is much too late for regular garbage collection. This patch proposes instead to store weak references in modules_by_index, so that extension modules can be collected in a normal way when they are removed from sys.modules.

The only gotcha is that PyState_FindModule returns a borrowed reference. With this change, it becomes really important to incref the returned reference as soon as possible.

components: Interpreter Core
files: wr_module_state.patch
keywords: patch
messages: 194571
nosy: brett.cannon, eric.snow, loewis, ncoghlan, pitrou, sbt
priority: normal
severity: normal
stage: patch review
status: open
title: Store weak references in modules_by_index
type: resource usage
versions: Python 3.4
Added file: http://bugs.python.org/file31180/wr_module_state.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list