jab
jab

Reputation: 5823

Way to kill python thread from inside thread?

I have some python code that currently performs expensive computation by performing the computation in parallel through many threads. For a given time period, many threads are created and started on the fly that share the same code which is explicitly stated within the run method of the thread. My question is how do I stop/kill a thread at the end of its run method? (the run is only called once) I need to do this in order to create more threads for the next batch of computation.

#Example

class someThread(threading.Thread):
    def __init__(self):
        #some init code
    def run(self):

        #Explicitly Stated Code without constant loops

        #Something performed to stop/kill this thread

Upvotes: 1

Views: 1718

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409166

You need to signal the main thread that the worker thread is done, and then call join on the thread.

Upvotes: 2

Related Questions