how to drop all thread ??

L

Leon

if class A(
use threading,thread module
) to produce 100 thread,how to drop its (100 thread) when its running
 
D

Diez B. Roggisch

Leon said:
if class A(
use threading,thread module
) to produce 100 thread,how to drop its (100 thread) when its running

By exiting. There is no other way to stop a thread by force. Of course you
can write a run()-method like this:


def run(self):
while self.running_condition:
# do something
pass

If that running-condition is queried often enough, you can stop the thread
by setting it to false.
 
P

Peter Hansen

Diez said:
Leon wrote:




By exiting. There is no other way to stop a thread by force.

Note that even trying to exit won't work, if the threads are not
marked as "daemon" threads... Only by calling .setDaemon(True) on
the threads before they are started will you be able to terminate
them all just by exiting.

-Peter
 
A

Andrew Koenig

This reply is off topic but I couldn't resist:

The best way to get rid of thread is to adopt a kitten.

In fact, one of my cats is named Snobol because she is such a good string
manipulator.
 
M

Michel Claveau - abstraction méta-galactique non t

Hi !

The best method, it is the suicide (of the threads).
 
C

Chris S.

Leon said:
if class A(
use threading,thread module
) to produce 100 thread,how to drop its (100 thread) when its running

As Roggisch suggests, the cleanest way is if the thread kills itself
once signaled by an exit condition. However, there is a non-orthodox way
of pseudo-forcibly killing threads by catching the kill signal in a
traceback. This method is summed up in Connelly Barnes's informal
KThread module:
http://www.google.com/[email protected]&rnum=1

Note it won't work in all cases, as it can't kill a thread that's made a
blocking system call. However, it may come in useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,212
Messages
2,571,101
Members
47,695
Latest member
KayleneBee

Latest Threads

Top