1

I have a thread pool with threads doing specific tasks. After the task is done, I let the run() method of a worker to terminate.

After this, should I explicitly kill the thread with sys.exit() ? I noticed that the worker thread persists in the background, even after the task is done.

What's the recommended way to purge old threads?

schlamar
  • 9,238
  • 3
  • 38
  • 76
Goro
  • 9,919
  • 22
  • 74
  • 108

1 Answers1

1

Executing sys.exit will quit the whole application. There is no need to do anything with a thread finished execution.

Fur further reference about stopping/killing a thread see this question.

Community
  • 1
  • 1
schlamar
  • 9,238
  • 3
  • 38
  • 76
  • Are the expired threads then automatically garbage-collected? I am assuming that since such a thread can still return is_alive() then it exists in the memory. In normal operation my program never calls sys.exit() – Goro Jun 08 '12 at 00:52
  • The thread object itself is not garbage collected as long as you have a reference to it. But the objects created in a thread get usually collected after a thread exists. But there are some cases when objects can't be collected, for example with cyclic dependencies. But this is a general problem and has nothing to do with threads. – schlamar Jun 08 '12 at 09:01