Skip to content

Commit dfe4bdd

Browse files
authored
Merge pull request #90 from SwayamInSync/workaround-cpython-149728-lazyimport-race
Pre-import numpy lazy submodules before running tests
2 parents 2b63d54 + ae21f08 commit dfe4bdd

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Pre-import numpy's lazy submodules in single-threaded context before
2+
# pytest-run-parallel forks workers. Works around CPython issue https://github.com/python/cpython/issues/149728
3+
# which causes numpy's lazy __getattr__ on rec/ma/linalg/fft/... to recurse
4+
# to RecursionError under concurrent first-touch from multiple threads.
5+
# Drop this file when CPython bugfix release happens.
6+
7+
import numpy
8+
9+
for _attr in (
10+
"linalg", "fft", "dtypes", "random", "polynomial", "ma",
11+
"ctypeslib", "exceptions", "testing", "matlib", "f2py",
12+
"typing", "rec", "char", "core", "strings",
13+
):
14+
getattr(numpy, _attr)
15+
del _attr

0 commit comments

Comments
 (0)