need some help with threading module...

Daniel Bickett dbickett at gmail.com
Mon Dec 27 00:59:28 CET 2004


I found your object-oriented approach, while admirable, a little
muddled. So rather than modify your code, I simply took the paragraph
you wrote describing the scenario and wrote my own.[1]

Instead of having the Controller query the Subject (not exactly
plausible), I had it wait for a signal (threading.Event) as set by the
Subject. You could also have it query a queue, as that is a generally
accepted and thread-safe object to use, but for this purpose I chose an
event and a global variable. (I'm aware that some would look down on
this, but I didn't see a problem, as it was only modified by one thread
amd printed by the other.)

Daniel Bickett

NOTES:

[1] Google killed my whitespace (as spaces _and_ tabs...) in the
previews, so I pasted it on Nopaste:
http://rafb.net/paste/results/KilM6t70.html




More information about the Python-list mailing list