New submission from kale-smoothie <suraj-patel...@outlook.com>:

Unless I've misread or misunderstood, the documentation at 
https://docs.python.org/3/reference/import.html#loaders for the deprecated 
`load_module` method doesn't indicate any requirements or caveats for thread 
safe importing. As it stands, I think it is not thread-safe, since the module 
is not protected against concurrent imports by the internal implementation 
marker `__spec__._initializing = True`.

Additionally, the deprecated function decorator, 
`importlib.util.module_for_loader` seems to implement the marker incorrectly 
(sets `__initializing__` directly on the module).

I think this behaviour should either be documented as a major caveat, or 
internal details exposed to allow thread-safe implementations, or the old API 
removed entirely.

----------
assignee: docs@python
components: Documentation
files: thread_unsafe_import.py
messages: 389713
nosy: docs@python, kale-smoothie
priority: normal
severity: normal
status: open
title: implementations of the deprecated load_module import loader API, as 
prescribed by the documentation, are not thread safe
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49916/thread_unsafe_import.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to