New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes import numpy as np
yields NameError: name 'testing' is not defined
#9931
Comments
I wonder if there's something funny going on with multiple threads trying to import numpy at the same time? I would have thought the interpreter's import lock would avoid that, but I don't know how it works in detail and I think it's changed over time. What version of Python are you using? |
@njsmith That makes a lot of sense. I can't prove the negative, but I've tested enough trials that I think this fixed my issue. Should the issue stay open for the purposes of general threading safety re: |
It's probably not a big priority, but I guess if someone can figure out what's going on in more detail it'd be nice to know (and possibly fix, if it's possible in a reasonable way). Unfortunately, I'm not finding much details about the import lock, and there's at least one note that circular imports may get special handling, which is something we could be hitting here (most of numpy's subpackages are going to have import cycles involving the root @standarddeviant What version of Python are you using? Maybe @ncoghlan will know off the top of his head? |
The gist of the current import lock semantics is that the global import lock now only protects a set of per-module-name locks, so different threads will only block each other if they're importing the same module (with deadlock detection to allow for circular dependencies). Original patch is at https://hg.python.org/cpython/rev/edb9ce3a6c2e, with the docs updates added to the now-legacy import lock manipulation API: https://docs.python.org/3/library/imp.html#imp.lock_held https://bugs.python.org/issue31070 is a recently fixed race condition in that logic which I suspect has been around since the original implementation of per-module import locks in 3.3 (we just didn't notice until now, when some changes to the test suite for other issues made it easier to hit the problem while running the importlib tests). So if you're able to try this out on Python 3.6.3, and can't readily reproduce the misbehaviour, then that's likely your culprit. |
@njsmith The python version I'm using is
I'll test out my code (with out the above fix) on on 3.6.3 per @ncoghlan's post. If I can make a short, simple script that exposes this behavior, I'll post it here. Thank you both for the help and information! |
Here's a very simple script that will expose the behavior:
When I run with no command line args, I upgraded to python 3.6.3, and the command line arg has no effect regarding exceptions thrown:
Closing the issue given that it seems to be fixed in 3.6.3. Thanks again! |
I'm seeing a strange error about numpy 'testing' not being defined on an import of numpy.
Here's the traceback:
I'm using a version of miniconda installed with numpy and other common packages.
The package doing this import is
soundfile
, but it looks like it's simply runningimport numpy as np
. With the exact same code and input wave files, I see this error about 1% of the time.By looking at
numpy/__init__.py
, I'm curious how testing is defined at all. It's not imported explicitly anywhere in the file. I noticed this is changed in master, but not yet in any release. Does anyone understand why this might work most of the time, but fail occasionally?The text was updated successfully, but these errors were encountered: