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: tempfile.TemporaryDirectory deleted after sleep in threads
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: colas.le.guernic
Priority: normal Keywords:

Created on 2021-05-10 21:39 by colas.le.guernic, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_tmpdir.py colas.le.guernic, 2021-05-10 21:39
mwe.py colas.le.guernic, 2021-05-11 07:44 with sleep instead of subprocess.run
Messages (3)
msg393436 - (view) Author: Colas Le Guernic (colas.le.guernic) * Date: 2021-05-10 21:39
Yet another weird bug when one creates sub-processes from threads.
I found several issues mentioning ThreadPoolExecutor and subprocess.run but I believe this one is different.

When creating a temporary directory with tempfile.TemporaryDirectory (with or without context manager) it is sometimes deleted by a call to subprocess.run when both occurs inside a task sent to a ThreadPoolExecutor created without a context manager (that last part is very odd).

Running the attached file on python 3.8.5 or 3.8.10 shows the issue only occurs if the executor is not created through a context manager.

The bug does not seem to occur on python 3.9.5 or 3.10.0b1.

Using a ProcessPoolExecutor seems to fix the issue too.
msg393445 - (view) Author: Colas Le Guernic (colas.le.guernic) * Date: 2021-05-11 07:44
Actually, it has nothing to do with subprocess.run, replacing that line with sleep(random()) exhibits the same behavior.
msg393446 - (view) Author: Colas Le Guernic (colas.le.guernic) * Date: 2021-05-11 08:06
I guess this will be a `won't fix` as python3.8 is now in security-fix only mode.
I was misled by https://www.python.org/downloads/ that still indicates a bugfix maintenance status.
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88271
2021-10-15 07:15:03serhiy.storchakasetstatus: open -> closed
resolution: out of date
stage: resolved
2021-05-11 08:06:05colas.le.guernicsetmessages: + msg393446
2021-05-11 07:53:41colas.le.guernicsetversions: + Python 3.6, Python 3.7
2021-05-11 07:44:44colas.le.guernicsetfiles: + mwe.py

messages: + msg393445
title: tempfile.TemporaryDirectory deleted after call to subprocess.run in threads -> tempfile.TemporaryDirectory deleted after sleep in threads
2021-05-10 21:57:39colas.le.guernicsetcomponents: + Library (Lib)
2021-05-10 21:39:01colas.le.guerniccreate