Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Reproducer
This program starts many threads racing to callsysconfig.get_config_var:
import sysconfigfrom multiprocessing.pool import ThreadPooldef thread(i): assert sysconfig.get_config_var("srcdir") is not Nonewith ThreadPool() as pool: pool.map(thread, range(100))When run with Python 3.11.0, this asserts as follows:
Traceback (most recent call last): File "/home/grees/core/junk.py", line 8, in <module> pool.map(thread, range(100)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/grees/github.com/cpython/Lib/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/grees/github.com/cpython/Lib/multiprocessing/pool.py", line 771, in get raise self._value ^^^^^^^^^^^^^^^^^ File "/home/grees/github.com/cpython/Lib/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) ^^^^^^^^^^^^^^^^^^^ File "/home/grees/github.com/cpython/Lib/multiprocessing/pool.py", line 48, in mapstar return list(map(*args)) ^^^^^^^^^^^^^^^^ File "/home/grees/core/junk.py", line 5, in thread assert sysconfig.get_config_var("srcdir") is not None ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionErrorAnalysis
In thesysconfig module,get_config_var callsget_config_vars which initializes the global variable_CONFIG_VARS in a thread-unsafe manner.
Use case
The reproducer above is simplified from a multi-threaded build system. Each build thread needs to get some information fromsysconfig, so that the threads are racing to be the first to callget_config_vars.
Workaround
Adding an initial call toget_config_vars before starting any thread ensures that_CONFIG_VARS is reliably initialized.
Metadata
Metadata
Assignees
Projects
Status
Done