John Dohn wrote:
When I do this, I put a special value in the queue (like None) and in
the worker thread, check for the special value and exit if found.
Threads can also be marked as "daemon threads" (see docs for
threading.Threa d objects). This will make the application terminate if
only "daemon threads" are left.
So best would probably be soemthing like
- call setDaemon() when creating worker threads
- ...
- send all worker/daemon threads None via queue
- wait some time, like time.sleep(1.0) , to let daemon exit themselves
- exit main application
-- Gerhard
Hi there,
>
How can I kill a threading.Threa d subclass from MainThread?
>
My threads are waiting for data in Queue.get() method:
class MyThread(thread ing.Thread):
def run(self):
while True:
data = queue.get() # <- here it waits most of the time
... process data
>
From the main thread I start several working threads:
thr = MyThread()
thr.start()
... feed the queue
and at the end for each thread I'd like to do something like thr.kill()
or thr.stop() or thr.destroy() or ... you got the point. I can't figure
out how.
>
Is there a way to do it?
>
How can I kill a threading.Threa d subclass from MainThread?
>
My threads are waiting for data in Queue.get() method:
class MyThread(thread ing.Thread):
def run(self):
while True:
data = queue.get() # <- here it waits most of the time
... process data
>
From the main thread I start several working threads:
thr = MyThread()
thr.start()
... feed the queue
and at the end for each thread I'd like to do something like thr.kill()
or thr.stop() or thr.destroy() or ... you got the point. I can't figure
out how.
>
Is there a way to do it?
the worker thread, check for the special value and exit if found.
Threads can also be marked as "daemon threads" (see docs for
threading.Threa d objects). This will make the application terminate if
only "daemon threads" are left.
So best would probably be soemthing like
- call setDaemon() when creating worker threads
- ...
- send all worker/daemon threads None via queue
- wait some time, like time.sleep(1.0) , to let daemon exit themselves
- exit main application
-- Gerhard
Comment