2

When using Thread objects from the threading module in python, do threads need to be joined in order to release all their resources?

From the pthread man pages :

"Only when a terminated joinable thread has been joined are the last of its resources released back to the system."

However the python threading documentation does not mention that a join is necessary to clean up resources, just that it waits for a thread to terminate. This question claims that a join in python does not do anything to the thread, but does not provide any evidence of why they think that.

So when using python do I need to call join on all my threads, to release all their resources?

XORNAND
  • 142
  • 1
  • 4
  • No. You do not need to join a thread for it to be able to release resources. Daemon threads, however, (which you never join, because they never terminate) are stopped abruptly on shutdown, therefore may not cleanup resources on shutdown. – sytech Mar 28 '18 at 15:42
  • @sytech is there documentation or source code that reflects that? I really would like a reference showing that this is true. – XORNAND Mar 28 '18 at 15:51
  • Showing what? Showing that the rules for Python threads are different from the rules for pthread threads? That might be hard to come by. – Solomon Slow Mar 28 '18 at 16:12
  • The docs probably don't mention it because it's not relevant. `threading` is a high-level interface, whereas you are referencing the posix pthread man page. Those concepts are low-level and, with respect to CPython, are implementation details that are not noteworthy. Plainly, from python, it's not necessary to call `join`; `threading.join` has nothing to do with `pthread_join`. At any rate, It should be simple enough to test yourself, if you want. What are you concerned about specifically? – sytech Mar 28 '18 at 16:57

0 Answers0