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

Fix the issue for NamedTemporaryFile() on Windows #6

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

hefengxian
Copy link
Contributor

Since last change about NamedTemporaryFile() function's option delete=False the temporary file will keep in tmp directory when program was finished. this PR for delete those temporary files automatically

Copy link
Owner

@MagedSaeed MagedSaeed left a 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()

Comment on lines +135 to +136
os.unlink(itmp.name)
os.unlink(otmp.name)
Copy link
Owner

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!

Copy link
Contributor Author

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

https://stackoverflow.com/questions/42636018/python-difference-between-os-remove-and-os-unlink-and-which-one-to-use

@hefengxian
Copy link
Contributor Author

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()

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

@hefengxian
Copy link
Contributor Author

hefengxian commented Jun 1, 2020

I have test in those platforms

  • macOS
    • OS version: catalina
    • Java version: 11.0
    • Result: pass
  • Ubuntu Server
    • OS version: 18.04.2
    • Java version: 1.8
    • Result: pass
  • Windows
    • OS version: 10
    • Java version: 1.8
    • Result: pass

and tmp dir no file left. when this merged i think the issue it should close

@MagedSaeed
Copy link
Owner

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?

@MagedSaeed
Copy link
Owner

I am merging the pull request right now.

@MagedSaeed MagedSaeed merged commit 420b97d into MagedSaeed:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants