1

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
jab
  • 5,673
  • 9
  • 53
  • 84

1 Answers1

2

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

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621