wasm-demo/demo/ermis-f/python_m/cur/0130

56 lines
1.6 KiB
Plaintext

From: sca at isogmbh.de (Chris...)
Date: Tue, 27 Apr 1999 12:05:51 GMT
Subject: threading/events questions
Message-ID: <3725a47f.96308574@scout>
Content-Length: 1391
X-UID: 130
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...