簡體   English   中英

oct2py - 使用python中的線程調用八度函數

[英]oct2py - Calling an octave function using threads in python

我試圖使用兩個線程從python程序調用Octave函數。 我的八度代碼只是為了看它是如何工作的 -

testOctave.m

function y = testOctave(i)
    y = i;
end

而python程序只是試圖調用它

from oct2py import octave
import thread
def func(threadName,i) :
    print "hello",threadName   // This printf works
    y = octave.testOctave(i)
    print y   // This is ignored
    print 'done'   // This is ignored
    print 'exiting'    // This is ignored

try:
    thread.start_new_thread( func, ("Thread-1", 100 ) )
    thread.start_new_thread( func, ("Thread-2", 150 ) )
except:
    print "Error: unable to start thread"

程序退出時不會出現任何錯誤,但在上面的函數中,只執行第一次打印,兩個線程都會忽略八度調用之后的所有打印。 是否有這種情況發生的原因,我該怎么做才能使它發揮作用?

該程序沒有做任何特別的事情,我只想弄清楚如何使用oct2py

oct2py創建者在這里。 從oct2py導入八度音程時,您正在導入Oct2Py類的便捷實例。 如果要使用多個線程,則必須導入Oct2Py並在線程函數內實例化或預分配,並將其作為參數傳遞給函數。 Oct2Py的每個實例都使用自己的Octave會話和專用的MAT文件進行I / O.

from oct2py import Oct2Py
import thread
def func(threadName,i) :
    oc = Oct2Py()
    y = oc.testOctave(i)
    print y

try:
    thread.start_new_thread( func, ("Thread-1", 100 ) )
    thread.start_new_thread( func, ("Thread-2", 150 ) )
except:
    print "Error: unable to start thread"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM