I agree with jmj's solution, you would want to send a signal of some
sort to Thread B from A when some event occurs in A. A queue is one
way to do it, but keep in mind that there are numerous ways to
communicate between threads/processes (queue, pipe, exit status,
TCP/UDP message, etc.). I believe one of the first couple chapters in
O'Reilly's "Programming Python" book discusses most of these methods.
Choose the simplest one that meets your needs.