It's pretty easy:
from threading import Thread
from Queue import Queue
# first create the 2 queues you need
quxxx = Queue(10)
quyyy = Queue(10)
# then write the functions that the 2 threads will execute.
# in the functions, put and get items from the queues as you like.
# don't forget to call queue.task_done() after each queue.get()
def funcA():
pass
def funcB():
pass
# then create the 2 threads
thA = Thread(target=funcA)
thB = Thread(target=funcB)
# then start the threads
thA.start()
thB.start()
# then wait for the threads completion
thA.join()
thB.join()
# the end
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
Many thanks for this it is a real help.
However, if I simply wanted to start only one thread that was seperate from the main thread, and use the two queues to pass data between the main thread and the other thread could I just use the start_new_thread function?
If you want to start a single thread, write the same code without funcB() and thB. The main thread can interact with thA through queues between thA.start() and thA.join().
It's not a good idea to use directly the methods of the thread module, like start_new_thread(). As the documentation says, this module contains low level functions. Use the module threading instead. Errors in thread programming may be difficult to track, and the module threading is safer.
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691