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

PermissionError ... cannot access the file because it is being used by another process: on Windows #27

Closed
engineerjoe440 opened this issue Aug 15, 2022 · 0 comments · Fixed by #28

Comments

@engineerjoe440
Copy link
Contributor

While running with the configuration shown in #26, additional Windows-related permission issues were found:

λ rich-codex --skip-git-checks
INFO     rich-codex ⚡️📖⚡️ version 1.2.1
INFO     Found 1 config file
INFO     Searching 1 files
╭──────────────────────────────┬──────────────────────────╮
│ Commands to run:             │                   Source │
├──────────────────────────────┼──────────────────────────┤
│ git-rtac compile --help      │  docs\img\rich-codex.yml │
│ git-rtac dependencies --help │  docs\img\rich-codex.yml │
│ git-rtac export --help       │  docs\img\rich-codex.yml │
│ git-rtac help                │  docs\img\rich-codex.yml │
│ git-rtac import --help       │  docs\img\rich-codex.yml │
│ git-rtac info --help         │  docs\img\rich-codex.yml │
╰──────────────────────────────┴──────────────────────────╯
Do you want to run these commands? (All / Some / None) [a/s/n]: a
INFO     Running all commands
Traceback (most recent call last):
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\Scripts\rich-codex.exe\__main__.py", line 7, in <module>
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\site-packages\rich_click\rich_command.py", line 19, in main
    rv = super().main(*args, standalone_mode=False, **kwargs)
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\joestan\Documents\(Other) Python Projects\rich-codex\src\rich_codex\cli.py", line 455, in main
    codex_obj.save_all_images()
  File "C:\Users\joestan\Documents\(Other) Python Projects\rich-codex\src\rich_codex\codex_search.py", line 410, in save_all_images
    img_obj.save_images()
  File "C:\Users\joestan\Documents\(Other) Python Projects\rich-codex\src\rich_codex\rich_img.py", line 577, in save_images
    tmp_path.unlink()
  File "C:\Users\joestan\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1343, in unlink
    self._accessor.unlink(self)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\joestan\\AppData\\Local\\Temp\\tmpue80aezp'

Suspected Cause:

After a little digging around, it seems that this is related to some behavior between Windows and mkstemp: https://stackoverflow.com/a/34717110/10406011

Suggested Resolution:

Thus, it seems like we just need to do an os.close(...) to handle closing the file before removing it. I've got a development branch to try tackling this, and I'll open a PR for your review very shortly! :)

@ewels ewels closed this as completed in #28 Aug 15, 2022
ewels added a commit that referenced this issue Aug 15, 2022
…error-for-temporary-files

Close file before removing to satisfy Windows requirements - Linked: #27
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 a pull request may close this issue.

1 participant