I have numba installed in a custom directory, which works fine when I use sys.path.insert to explicitly add it to the path (I do not want to use virtual environments here). However, it doesn’t seem to work with a combination of objmode() and cProfile. Here is a minimal example:
import sys
sys.path.insert(0, '/tmp/test/lib64/python3.8/site-packages')
import numba
#@numba.njit
def testpath():
with numba.objmode():
print(sys.path)
#path = sys.path
testpath()
A) If I run this script directly (numba_profile_test.py
), it works fine – it prints out the value of sys.path as expected. (I can also uncomment @numba.njit
and it works fine).
B) If I run this script with cProfile (python -m cProfile -o cprofile.out numba_profile_test.py
), it works fine.
C1) If I uncomment @numba.njit
and run this script with cProfile, I get the following error:
Traceback (most recent call last):
File "/usr/lib64/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib64/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/lib64/python3.8/cProfile.py", line 196, in <module>
main()
File "/usr/lib64/python3.8/cProfile.py", line 189, in main
runctx(code, globs, None, options.outfile, options.sort)
File "/usr/lib64/python3.8/cProfile.py", line 19, in runctx
return _pyprofile._Utils(Profile).runctx(statement, globals, locals,
File "/usr/lib64/python3.8/profile.py", line 62, in runctx
prof.runctx(statement, globals, locals)
File "/usr/lib64/python3.8/cProfile.py", line 100, in runctx
exec(cmd, globals, locals)
File "numba_profile_test.py", line 13, in <module>
testpath()
NameError: global name 'sys' is not defined
C2) If I also uncomment the line path = sys.path
and run with cProfile, I get a different error:
Traceback (most recent call last):
File "/usr/lib64/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib64/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/lib64/python3.8/cProfile.py", line 196, in <module>
main()
File "/usr/lib64/python3.8/cProfile.py", line 189, in main
runctx(code, globs, None, options.outfile, options.sort)
File "/usr/lib64/python3.8/cProfile.py", line 19, in runctx
return _pyprofile._Utils(Profile).runctx(statement, globals, locals,
File "/usr/lib64/python3.8/profile.py", line 62, in runctx
prof.runctx(statement, globals, locals)
File "/usr/lib64/python3.8/cProfile.py", line 100, in runctx
exec(cmd, globals, locals)
File "numba_profile_test.py", line 13, in <module>
testpath()
SystemError: CPUDispatcher(<function testpath at 0x7f65c1ff11f0>) returned NULL without setting an error
Why does objmode() seem to interfere with cProfile here? And what does the NULL error mean?