Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 'tempfile.mkdtemp' with 'tempfile.TemporaryDirectory'. #4336

Closed
greschd opened this issue Aug 28, 2020 · 1 comment · Fixed by #5639
Closed

Replace 'tempfile.mkdtemp' with 'tempfile.TemporaryDirectory'. #4336

greschd opened this issue Aug 28, 2020 · 1 comment · Fixed by #5639
Assignees
Labels
Milestone

Comments

@greschd
Copy link
Member

greschd commented Aug 28, 2020

The tempfile.mkdtemp() is used in many places in the code to create a temporary directory, that is later cleaned up manually (e.g. with shutil.rmtree). The drawback of this is that the cleanup will not happen if execution is somehow interruped.

By using tempfile.TemporaryDirectory() instead (even when a context manager cannot be used), cleanup will happen when the garbage collector picks up the object. The "manual" cleanup should still be kept, as calling the .cleanup() method - because the garbage collector doesn't run at predictable intervals.

See comment by @ltalirz in #4220 (comment)_

@sphuber
Copy link
Contributor

sphuber commented Aug 28, 2020

Note that when this concerns tests, written for pytest, they should even probably use the tmpdir or tmp_path builtin fixtures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants