I am trying following code with python3:
import time
duration = 5
from numba import njit
@njit
def myfn():
num = 3
starttime = time.time()
while True:
print("Checking", num)
endtime = time.time()
if (endtime - starttime) > duration:
print("Time up.")
return
num += 2
myfn()
However, it is giving following error:
Traceback (most recent call last):
File "/home/abcde/testing_numba", line 20, in <module>
myfn()
File "/home/abcde/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 414, in _compile_for_args
error_rewrite(e, 'typing')
File "/home/abcde/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 357, in error_rewrite
raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'time' of type Module(<module 'time' (built-in)>)
File "testing_numba", line 11:
def myfn():
<source elided>
num = 3
starttime = time.time()
^
During: typing of get attribute at /home/abcde/testing_numba (11)
File "testing_numba", line 11:
def myfn():
<source elided>
num = 3
starttime = time.time()
^
Especially note Unknown attribute 'time' of type Module(<module 'time' (built-in)>)
Without numba, the code works fine.
How can this error be corrected?