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] Fix the permission denied error on windows. #1077

Merged
merged 7 commits into from
Jun 24, 2021

Conversation

fjfzlzj
Copy link
Contributor

@fjfzlzj fjfzlzj commented Jun 4, 2021

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

To fix the permission denied error when using '--resuming-from' on Windows. [#1063] [#4966(mmdet)]
I'm not sure whether that modification will cause any problems on other platforms or not, so I add an 'if' to ensure Windows only.

Modification

Modify the behavior of loading config on Windows:

  • Temporary file now will be closed without being deleted before reading on Windows.
  • When read ends, it will be deleted by os.unlink.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@codecov
Copy link

codecov bot commented Jun 4, 2021

Codecov Report

Merging #1077 (9b51959) into master (d212bd5) will increase coverage by 1.92%.
The diff coverage is 100.00%.

❗ Current head 9b51959 differs from pull request most recent head e9c54ad. Consider uploading reports for the commit e9c54ad to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1077      +/-   ##
==========================================
+ Coverage   65.72%   67.64%   +1.92%     
==========================================
  Files         157      159       +2     
  Lines       10092    10281     +189     
  Branches     1828     1856      +28     
==========================================
+ Hits         6633     6955     +322     
+ Misses       3113     2961     -152     
- Partials      346      365      +19     
Flag Coverage Δ
unittests 67.64% <100.00%> (+1.92%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcv/utils/config.py 89.88% <100.00%> (+0.02%) ⬆️
mmcv/ops/multi_scale_deform_attn.py 58.40% <0.00%> (-11.29%) ⬇️
mmcv/utils/ext_loader.py 35.89% <0.00%> (-2.34%) ⬇️
mmcv/runner/fp16_utils.py 58.12% <0.00%> (-1.61%) ⬇️
mmcv/runner/hooks/optimizer.py 16.66% <0.00%> (-1.08%) ⬇️
mmcv/ops/__init__.py 100.00% <0.00%> (ø)
mmcv/cnn/bricks/__init__.py 100.00% <0.00%> (ø)
mmcv/cnn/bricks/registry.py 100.00% <0.00%> (ø)
mmcv/runner/hooks/logger/__init__.py 100.00% <0.00%> (ø)
mmcv/runner/hooks/logger/dvclive.py 86.36% <0.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d212bd5...e9c54ad. Read the comment docs.

@wangruohui
Copy link
Member

wangruohui commented Jun 14, 2021

As a suggestion, a cleaner way is :

with tempfile.NamedTemporaryFile('w', delete=False, suffix=file_format) as temp_file:
    temp_file.write(cfg_str)
cfg = Config.fromfile(temp_file.name)
# see PR #1077 for more detail
os.unlink(temp_file.name)

This should work for both windows and linux.
The reason is not "the file is deleted when reading", instead , the reason is that, on windows, a file cannot be opened twice. Here, temp_file is opened first in the with statement and second in function from_file thus resuting the error on windows.

So as a potentially more stable solution, just create the file on disk, run fromfile, then delete it, all manually.

@fjfzlzj
Copy link
Contributor Author

fjfzlzj commented Jun 15, 2021

Thanks for the suggestion. I add [#4966(mmdet)] to comment and modify code as your suggest.

use os.unlink instead of unlink
Copy link
Member

@wangruohui wangruohui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

mmcv/utils/config.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@zhouzaida zhouzaida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hellock
Copy link
Member

hellock commented Jun 16, 2021

A comment may be left to note windows compatibility.

mmcv/utils/config.py Outdated Show resolved Hide resolved
@zhouzaida zhouzaida mentioned this pull request Jun 21, 2021
13 tasks
@OpenMMLab-Coodinator
Copy link

Hi @fjfzlzj !First of all, we want to express our gratitude for your significant PR in this project. Your contribution is highly appreciated, and we are grateful for your efforts in helping improve this open-source project during your personal time. We believe that many developers will benefit from your PR.

We would also like to invite you to join our Special Interest Group (SIG) private channel on Discord, where you can share your experiences, ideas, and build connections with like-minded peers. To join the SIG channel, simply message moderator— OpenMMLab on Discord or briefly share your open-source contributions in the #introductions channel and we will assist you. Look forward to seeing you there! Join us :https://discord.gg/UjgXkPWNqA

If you have WeChat account,welcome to join our community on WeChat. You can add our assistant :openmmlabwx. Please add "mmsig + Github ID" as a remark when adding friends:)
Thank you again for your contribution❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants