-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fix the issue for NamedTemporaryFile() on Windows #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this still will have the issue that the temporary file will not be deleted on program crash or CTRL+C signal, does not it?
How about applying some ideas from here[https://stackoverflow.com/questions/3850261/doing-something-before-program-exit]?
How about this snippet?
try:
...
except KeyboardInterrupt:
# clean up
exit()
os.unlink(itmp.name) | ||
os.unlink(otmp.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this part platform independent? That is interesting!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked Python docs, os.unlink()
is the same with os.remove()
and it Unix & Windows both available
But there is an option to use pathlib.Path.unlink(file.name)
check here
I have on idea about this, but i think this is not a good solution, sometimes i'm using PyCharm run & stop button, i'm not sure what signal is send by stop button; but also cause the temporary file not removed |
I have test in those platforms
and tmp dir no file left. when this merged i think the issue it should close |
I think we should merge, then update the pypi package with what we have right now. Further modifications will be added later. What do you think? |
I am merging the pull request right now. |
Since last change about
NamedTemporaryFile()
function's optiondelete=False
the temporary file will keep in tmp directory when program was finished. this PR for delete those temporary files automatically