This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Resource leaks with threading.Thread
Type: resource usage Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: POCEH, martin.panter, rahul-kumi, vstinner
Priority: normal Keywords:

Created on 2020-05-17 08:07 by POCEH, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
thread.py POCEH, 2020-05-17 08:07
Messages (3)
msg369102 - (view) Author: Rosen Tomov (POCEH) Date: 2020-05-17 08:07
In my project I'm using intensively threading to transfer HTTP data - reading is in separate thread and the process run smoothly. However when I've try to optimize stopping of the process and attempt to use the daemon threads. The result was 'Can't start new thread' error under Linux. In order to investigate the issue I've create small test program and found more interesting problem: using non daemon threads leaks handles (under Windows/x64 Semaphore type), while under Linux looks like leaks some other resource, can't say exactly what. When using a daemon threads no leaks handles under Windows but under Linux, after long time running the problem arrives, the only one solution is to reboot of Linux/ARM64, restarting the Python process didn't help! Of course the problem could be race condition or some locking problem, didn't investigate further and in Python's core source. 
Attached test programs reveals the problem very quickly, using Python 3.8.x interpreters. Also I've testing with lambdas and deletion and found that they do not influence the behavior.
msg369762 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2020-05-24 01:01
Perhaps this is the same as Issue 37788, introduced in 3.7.
msg402575 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-24 15:59
You must join thread using thread.join().

If I add .join() calls, threading.active_count() stays around 2, it doesn't grow.

It's not a bug in Python.
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84837
2021-09-24 15:59:35vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg402575

stage: resolved
2020-05-24 01:13:50ned.deilysetnosy: + vstinner
2020-05-24 01:01:25martin.pantersetnosy: + martin.panter
messages: + msg369762
2020-05-18 16:39:34rahul-kumisetnosy: + rahul-kumi
2020-05-17 08:07:51POCEHcreate