繁体   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