I have some modules in different packages for my project. This project requires several threads which might be started in different modules, and I intend to use queues for the inter-thread communication.
Is there a way to pass a queue created in one module for use in another module?
# 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)
A Queue is not different from any other object, in that if it is defined at module level in one module you can import that module and access it directly:
import ModuleA
# now ModuleA.myQueue is the Queue object created there
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With