-
Notifications
You must be signed in to change notification settings - Fork 16
Try_except with warning #68
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
Try_except with warning #68
Conversation
| try: | ||
| self._uncompressed_folder_handle.cleanup() | ||
| except PermissionError: | ||
| logging.error("Windows PermissionError, temporary directory {}" + |
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 going to reraise the error in all cases? I wonder whether you want to implement a custom error and raise that instead, or reraise the original error with the new error message, rather than log.
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.
Do we want to code to execute and let the user go delete files manually (or fix permission) or crash?
I was thinking 'Keep going, but warn the user this is taking up disk space'
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.
Gotcha. Yes, that makes sense.
|
Regarding differences with DIPY, I agree that it's very strange. Maybe you can initialize the temporary directory in the same place that we put data? |
|
I just remove the concurrency lines to investiguate, if this is the source maybe changing the folder is the easiest solution and still safe (since we will know what is the source) Hopefully, tomorrow this will be solved. Getting close! |
|
it would be great to reproduce the error here. I do not believe that the user will try to find the folder and delete manually. Actually, there are some chances that even manually, he will not be able to delete the folder. He will have to kill the terminal and then be able to delete the folder. I think the file do not close because he still have an active reference somewhere. In the case of DIPY, it might be some design issue, I am not sure. I did not check your test here but do you have such an example.
|
|
@skoudoro I just added test_close_tmp_file to do explicitly what you said and it is still passing. When loading the trx zip file, it creates a tmp folder, then I create a SFT, close the TRX and then I
|
|
Do you want to add a test with a context manager here, to see if that's somehow messing things up? |
|
I am not sure how to do that since I create the tmp directory in the class, and I want to keep it active outside of the scope of the |
|
I think your test is not complete. In your test.
|
|
Sorry, I missed the second loading on my previous description |
|
I added a second loading (of the same trx), checking the data, then closing it again. I also made the deepcopy of the tmp_dir.name (just a str) clearer so it is safer (just a string) |
|
@arokem @skoudoro my new test is much more direct. Earlier I was checking if the folder stopped existing, now I am using psutil to actually check if there are any opened files by the process. And they are passing (on github, on my linux & windows). So I think its all working as intended, but all of these new tests are very good to have! (even if I have no idea why it is not working in Dipy) |
@arokem I don't understand why tempfile.gettempdir() is returning a path for which we can't delete (PermissionError) in the Dipy test (but our pass).
What do you think? @skoudoro ? What I added in this PR is probably a good practice (trying to delete the folder, catch an error, and give a better error message).
On top of this for Dipy in my tests, I could set the environment variable (os.getenv('TRX_TMPDIR')) to some path I do have permissions (any suggestion of a path directory that I could use?)