Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@frheault
Copy link
Collaborator

@frheault frheault commented Oct 9, 2023

@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?)

try:
self._uncompressed_folder_handle.cleanup()
except PermissionError:
logging.error("Windows PermissionError, temporary directory {}" +
Copy link
Collaborator

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.

Copy link
Collaborator Author

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'

Copy link
Collaborator

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.

@arokem
Copy link
Collaborator

arokem commented Oct 9, 2023

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? op.join(os.expanduser('~'), '.dipy')

@frheault
Copy link
Collaborator Author

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!

@skoudoro
Copy link
Collaborator

skoudoro commented Oct 10, 2023

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, sft reference is still active when you close, and you still use sft which have a reference to the file. (due to memory map)

it might be some design issue, I am not sure. I did not check your test here but do you have such an example.

  1. load trx
  2. create a reference
  3. close TRX
  4. still doing something with the reference.
  5. check if TRX was closed or still open because of the reference.

@frheault
Copy link
Collaborator Author

@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

  • Verify the folder does not exist
  • Check the SFT
  • Call sft.to_vox()
  • Check the SFT again

@arokem
Copy link
Collaborator

arokem commented Oct 10, 2023

Do you want to add a test with a context manager here, to see if that's somehow messing things up?

@frheault
Copy link
Collaborator Author

frheault commented Oct 10, 2023

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 __init__ and pass the trx around freely.

@skoudoro
Copy link
Collaborator

I think your test is not complete. In your test.

  • you should remove tmp_dir = deepcopy(trx._uncompressed_folder_handle). (this is something you do not do in DIPY)
  • after sft.to_vox() you should load again (call trx = tmm.load(path)). This second load should not fail. This is what is happening is DIPY, the second load is failing because it believe that the file is still open / use

@skoudoro
Copy link
Collaborator

Sorry, I missed the second loading on my previous description

@frheault
Copy link
Collaborator Author

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)

@frheault
Copy link
Collaborator Author

frheault commented Oct 10, 2023

@arokem @skoudoro my new test is much more direct. test_close_tmp_files

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)

@frheault frheault merged commit ef5f407 into tee-ar-ex:master Oct 10, 2023
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.

3 participants