[issue9260] A finer grained import lock

Antoine Pitrou report at bugs.python.org
Wed Jul 14 16:44:23 CEST 2010

New submission from Antoine Pitrou <pitrou at free.fr>:

This is an implementation of the idea suggested in:

The patch creates a dictionary of reentrant locks keyed by module full name. Trying to import a module or package will first get the lock for that module (or, if necessary, create it) and then acquire it. This is done for any module type.

The global import lock is still there, but only used for two things:
- serializing first time creation of module-specific locks
- protection of imports based on import hooks, since we don't know whether third-party import hooks are themselves thread-safe

Semantics of the public C API are unchanged, because it is not clear whether they should be or not (concerns of usefulness vs. compatibility). For example, PyImport_ImportModuleNoBlock() still uses the global import lock but this could be relaxed in a later patch.

components: Interpreter Core
files: implock.patch
keywords: patch
messages: 110287
nosy: brett.cannon, christian.heimes, grahamd, gvanrossum, ncoghlan, pitrou
priority: normal
severity: normal
status: open
title: A finer grained import lock
type: feature request
versions: Python 3.2
Added file: http://bugs.python.org/file17998/implock.patch

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list