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

wip_dir Context Manager Rename Retry #639

Merged
merged 3 commits into from
Jun 19, 2023
Merged

wip_dir Context Manager Rename Retry #639

merged 3 commits into from
Jun 19, 2023

Conversation

TManzini
Copy link
Contributor

@TManzini TManzini commented Jun 19, 2023

This fix will attempt to rename the temporary folder for 10sec. This is due to an issue on windows machines that causes the renaming of the temporary folder to result in a PermissionError for several seconds after the last image is written.

This fix will attempt to rename the temporary folder for 10sec. This is due to an issue on windows machines that causes the renaming of the temporary file to result in a PermissionError for several seconds after the last image is written.
@facebook-github-bot
Copy link
Contributor

Hi @TManzini!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@ptpt
Copy link
Member

ptpt commented Jun 19, 2023

Thanks for the PR @TManzini

Could you provide more context on the permission issue (e.g. any links)?

mapillary_tools/sample_video.py Outdated Show resolved Hide resolved
mapillary_tools/sample_video.py Outdated Show resolved Hide resolved
@TManzini
Copy link
Contributor Author

TManzini commented Jun 19, 2023

Sure, unfortunately the details around this behavior are poorly documented, but here is the trail that I followed to arrive at the PR.

When running the process_video script I kept getting PermissionError: [WinError 5] Access is denied: <PATH_TO_WIP_DIR> -> <PATH_TO_DONE_DIR>

  • I traced this to the rename() call referenced in the PR.
  • pathlib.Path.rename() relies on os.rename()
  • os.rename() does not have any documentation for PermissionError [WinError 5], likely because it is the result of some os specific function, but it has been observed in a number of places 1, 2.
  • Python does not handle edge cases like this as they are considered low level os details that would be too much effort to maintain. The most relevant discussion as it relates to this PR is this thread where a user calls out this specific behavior, and the issue is closed as not a bug because python does not wish to handle the edge case.

So the suggestion is to continuously retry the rename for a certain amount of time until the OS realizes the rename is okay, or it times out. I set 10s as an arbitrary number. This behavior only seems to occur on windows.

@ptpt
Copy link
Member

ptpt commented Jun 19, 2023

Thanks for the context! Lets narrow the hack to the windows platform only.

@ptpt
Copy link
Member

ptpt commented Jun 19, 2023

@TManzini If you could sign the CLA above, I'm happy to merge the PR to a branch and I will fix some minor issues there.

@TManzini
Copy link
Contributor Author

Let me know if you are happy with this implementation

@ptpt ptpt merged commit d302e65 into mapillary:main Jun 19, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants