Skip to content

bpo-33753: Refactor creating temporary files in test_fileinput. #7377

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

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jun 4, 2018

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. addCleanup() is a good solution.

I asked a question, but it shouldn't be a blocker issue.

count = 0
def writeTmp(self, content, *, mode='w'): # opening in text mode is the default
self.count += 1
name = TESTFN + str(self.count)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using tempfile.mktemp()? tempfile uses a temporary directory which is cleared sometimes at system boot. It prevents leaking temporary files if Python does crash.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I proposed mktemp() but mkstemp() may be even better.

@serhiy-storchaka
Copy link
Member Author

mktemp() is half-deprecated. THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED.

@serhiy-storchaka serhiy-storchaka merged commit 5f48e26 into python:master Jun 5, 2018
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the test_fileinput-writeTmp branch June 5, 2018 09:08
@bedevere-bot
Copy link

GH-7417 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 5, 2018
@miss-islington
Copy link
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5f48e2644dcfb47f0bbc0fcdc2b103a19bdec288 3.6

miss-islington added a commit that referenced this pull request Jun 5, 2018
)

(cherry picked from commit 5f48e26)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jun 5, 2018
@bedevere-bot
Copy link

GH-7431 is a backport of this pull request to the 3.6 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants