从python中的线程检索数据

时间:2014-08-01 02:18:11

标签: python multithreading

我在python中有一个处理OSC数据包的线程... 我需要在main函数中从osc中检索数据。如何从线程中获取数据? 以下是演示我的问题的代码:

尝试类别,但仍然“数据未定义

import OSC
import threading
import atexit
#------OSC Server-------------------------------------#
receive_address = '127.0.0.1', 7402

# OSC Server. there are three different types of server. 
s = OSC.ThreadingOSCServer(receive_address)

# this registers a 'default' handler (for unmatched messages)
s.addDefaultHandlers()

class receive:
    def printing_handler(addr, tags, data, source):

        if addr=='/data':
            self.data=data.pop(0)
            s.addMsgHandler("/data", printing_handler)
            return data



    def main(self):
        # Start OSCServer
        #Main function...I need to retrieve 'data' from the OSC THREAD here
        print "Starting OSCServer"
        st = threading.Thread(target=s.serve_forever)
        st.start()


reception=receive()
reception.main()
plouf = data.reception()
print plouf

提前致谢

1 个答案:

答案 0 :(得分:1)

使用标准库中的Queue,或使用全局变量。