[Python-de] AW: [Python-de] Threadrätsel
Gerson Kurz
Gerson.Kurz at t-online.de
Mon Jul 15 21:20:24 EDT 2002
Anfängerfehler. Das ist der Code nochmal abgespeckt
import threading, Queue
class DeviceHandler(Queue.Queue):
def run(self):
while self.get():
opt.put( None )
class OperationThread(Queue.Queue):
def run(self):
print "%s starts" % threading.currentThread()
dh.put( 42 )
self.get()
mainMessageLoop.put(60)
dh, opt = DeviceHandler(), OperationThread()
threading.Thread( target = dh.run ).start()
threading.Thread( target = opt.run ).start()
mainMessageLoop = Queue.Queue()
while 1:
msg = mainMessageLoop.get()
if msg:
print "mainMessageLoop got %s" % msg
mainMessageLoop.put(None)
threading.Thread( target = opt.run ).start()
else:
break
Was passiert- ich kriege None, gehe aus der While-schleife raus, aber das
Programm beendet sich nicht...weil der dh-thread noch lebt :(
More information about the Python-de
mailing list