2015-10-13 110 views
1

我正在編譯問題KeyboardInterrupt使用Continuum Numba模塊的異常。這裏是我的數據採集代碼:Numba和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

代碼的格式是相當搞砸了(說不出哪裏凹槽應該是),但我可以推測,在numba JIT ISN真的不會爲你做很多事情。它不會加速任意python代碼,並且只會使用標量和numpy數組(不是熊貓)爲數值材料提供良好的結果。我認爲你是在錯誤的層面上應用它。 – JoshAdel

回答

1

感謝特拉維斯的創新團隊的努力numba是一個偉大而強大的科學計算工具。但是,我們應該小心謹慎地在可行的情況下使用它,並且這種編輯可以爲我們的艱苦和快速生活帶來一些成果。

Numba文檔指出此明確,他說:

2.4.1.1. Constructs

Numba strives to support as much of the Python language as possible, but some language features are not available inside Numba-compiled functions:

- Function definition

- Class definition

- Exception handling (try .. except, try .. finally)

- Context management (the with statement)

- Comprehensions (either list , dict , set or generator comprehensions)

- Generator delegation (yield from)


The raise statement is supported in several forms:

raise (to re-raise the current exception)
raise SomeException
raise SomeException(<arguments>) : in nopython mode, constructor arguments must be compile-time constants

Similarly, the assert statement is supported with or without an error message.