使用Continuum Numba模块编译<strong> KeyboardInterrupt
异常时遇到问题。这是我的数据采集代码:
@jit
def lockinmeasurement(x):
Measurement=np.empty((0,5))
XMeas=np.empty((0,2))
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path_to_watch, recursive=True)
observer.start()
try:
while x:
SQData=pd.read_csv(path_to_watch,sep=',',skiprows=14)
Temp=SQData['Temperature (K)']
Field=SQData['Field (Oe)']
XMeas=np.append(XMeas,[[time.clock(),lockin.x]],axis=0)
Measurement=np.append(Measurement,[[a,b,c,d,e]])
p1.plot(XMeas,clear=True,label='Lockin X',pen='y')
pg.QtGui.QApplication.processEvents()
rd=pd.DataFrame(Measurement)
rd.to_csv('fileout.csv',sep='\t',index=False)
time.sleep(0.2)
except KeyboardInterrupt:
print('interrupted!')
lockinmeasurement(True)
在没有“ @jit
”的情况下,代码编译完全正常,但是当我尝试使用numba
时,它会返回错误:
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\numba\bytecode.py", line 231, in next
info = BYTECODE_TABLE[opcode]
KeyError: 121
During handling of the above exception, another exception occurred:
lockinmeasurement(True)
File "C:\Anaconda3\lib\site-packages\numba\dispatcher.py", line 165, in _compile_for_args
return self.compile(sig)
File "C:\Anaconda3\lib\site-packages\numba\dispatcher.py", line 303, in compile
flags=flags, locals=self.locals)
File "C:\Anaconda3\lib\site-packages\numba\compiler.py", line 595, in compile_extra
return pipeline.compile_extra(func)
File "C:\Anaconda3\lib\site-packages\numba\compiler.py", line 316, in compile_extra
raise e
File "C:\Anaconda3\lib\site-packages\numba\compiler.py", line 311, in compile_extra
bc = self.extract_bytecode(func)
File "C:\Anaconda3\lib\site-packages\numba\compiler.py", line 303, in extract_bytecode
bc = bytecode.ByteCode(func=self.func)
File "C:\Anaconda3\lib\site-packages\numba\bytecode.py", line 333, in __init__
table = utils.SortedMap(ByteCodeIter(code))
File "C:\Anaconda3\lib\site-packages\numba\utils.py", line 109, in __init__
for i, (k, v) in enumerate(sorted(seq)):
File "C:\Anaconda3\lib\site-packages\numba\bytecode.py", line 235, in next
raise NotImplementedError(ts % tv)
NotImplementedError: offset=80 opcode=0x79 opname=SETUP_EXCEPT
有什么办法可以解决这个问题吗?
答案 0 :(得分:1)
感谢Travis的创新团队的努力hero.equip(apple) # no error
hero.weapon.calculateDamage() # AttributeError: Apple object has no attribute `damage`
是一个伟大而强大的科学计算工具。然而,在可行的情况下,人们应该小心使用它,numba
- 汇编可以为我们艰难而快速的生活带来一些成果。
Numba Documentation明确说明了这一点,并说:
<强> 2.4.1.1。构建体强>
Numba努力支持尽可能多的Python语言,但 Numba编译函数中的一些语言特性不可用:
- 功能定义
- 分类定义
- 异常处理jit
- 上下文管理((try .. except, try .. finally)
语句)
- 理解(with
,list
,dict
或生成器理解)
- 发电机代表团(set
)来自)
yield
声明 声明支持多种形式:
raise
(重新提高当前例外)
raise
raise SomeException
:在raise SomeException(<arguments>)
模式下,构造函数参数必须是编译时常量
同样,支持nopython
语句,无论是否有错误消息。