Yan*_* Yi 3 python queue multithreading python-2.7
我的项目在不同的包中有一些模块。这个项目需要几个可能在不同模块中启动的线程,我打算使用队列进行线程间通信。
有没有办法传递在一个模块中创建的队列以供另一个模块使用?
# ModuleA.py
myQueue = Queue.Queue()
thread = myThread(threadID1, tName1, myQueue)
thread2 = myThread(threadID2, tName2, myQueue)
# ModuleB.py
myQueue = get_the_previous_queue_created() # possible?
thread3 = myThread(threadID3, tName3, myQueue)
Run Code Online (Sandbox Code Playgroud)
队列与任何其他对象没有什么不同,因为如果它是在一个模块的模块级别定义的,您可以导入该模块并直接访问它:
import ModuleA
# now ModuleA.myQueue is the Queue object created there
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1798 次 |
| 最近记录: |