threading/events questions
Chris...
sca at isogmbh.de
Tue Apr 27 08:05:51 EDT 1999
Hello...
After experimenting with the modules thread and threading I have
some open questions. I've written the famous ping-pong program
-----------------------------------------------------------------------------------------------------
from Threading import *
from time import sleep
Quit = Event()
def f(t, msg):
print msg
Quit.wait(t)
if Quit.isSet():
return
f(t, msg)
def run():
t1 = Thread(target=f, args=(10, 'ping'))
t2 = Thread(target=f, args=(5, '\tpong'))
t1.start()
t2.start()
sleep(60)
Quit.set()
-----------------------------------------------------------------------------------------------------
With that program, the threads are running for 60 seconds. But, how
can I stop one thread and not both? I don't want to write an
additional function doing exactly the same except dealing with a
different Event.
My second problem is sending an event with a message.
ChangeOutput = Event()
and send the event ChangeOutput('something different than ping-pong')
to one thread. After receiving this message, the thread should change
the recursive call to f(t, 'something different, than ping-pong').
How can I wait for events (more than one)? In the code above, I am
just waiting for one event with a proper timeout. How can I react on
the additional event ChangeOutput?
Thanks a lot in advance!
bye
Chris...
More information about the Python-list
mailing list