bpo-30814: Fixed a race condition when import a submodule from a package. by serhiy-storchaka · Pull Request #2580 · python/cpython (original) (raw)
Calling Python method from the C code is not much simpler than generating an exception.
The module is None
case isn't worth optimization. This isn't common case and isn't performance critical case since raising and catching exception is slow. Only the case of already imported module is worth optimization by implementing in C. It was my mistake that I implemented the generating an exception on C in 133138a, but my patch didn't touched Python code at all.
Note that the new _find_and_load()
is just a second half of old _gcd_import()
. All these checks already were implemented in Python, I just moved the code from one Python function to the other.
If you prefer I can withdraw changes in import.c
and create separate PR for simplifying C code (move locking and generating an exception to Python code) in master only.
I also can implement the second check in C and keep Python code unchanged. But I think that it is better to implement performancy non-critical parts in Python.