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

Re-opening open NamedTemporaryFile files won't work on Windows #6

Open
BramVanroy opened this issue Jun 30, 2018 · 5 comments
Open

Comments

@BramVanroy
Copy link

BramVanroy commented Jun 30, 2018

I was hoping there was an aligner that actually worked on Windows, but unfortunately it doesn't. The first issue I bump into is the file handling.

On Windows you can't re-open NamedTemporaryFile files that are open - it will give a Permission Denied error.

EDIT: I spoke before my turn. The issue seems more intricate than what I had assumed. Apologies. The issue remains, though.

Trace:

PS C:\tools\eflomal> python .\align.py -s .\source.txt -t .\target.txt
Traceback (most recent call last):
  File ".\align.py", line 142, in <module>
    if __name__ == '__main__': main()
  File ".\align.py", line 136, in main
    use_gdb=args.debug)
  File "python\eflomal\eflomal.pyx", line 123, in eflomal.align
    with open(source_filename, 'rb') as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\user\\AppData\\Local\\Temp\\tmphqbksy6m'
@BramVanroy BramVanroy changed the title Won't work on Windows Re-opening open NamedTemporaryFile files won't work on Windows Jun 30, 2018
@Nouran-Khallaf
Copy link

i am facing the same problem did you find a solution?

@BramVanroy
Copy link
Author

Alas, no. Did not get any feedback from authors.

@robertostling
Copy link
Owner

Hi, sorry I missed this. Unfortunately I don't have a Windows system to test on, so I can't debug this on my own. If anyone comes up with a portable solution I would be happy to accept it as a pull request. An emergency measure would be to add an option that creates a temporary file in a less secure way. Would that be acceptable for your use case?

@Nouran-Khallaf
Copy link

yes, I tried to add a specific location for the temp files but it did not work, please if you have any solution to specify the place it will be great. Many thanks

@TommiNieminen
Copy link

This is apparently a difference between Unix and Windows, Windows doesn't allow you to open a NamedTemporaryFile again. As a workaround, you can add "delete=False" to the NamedTemporaryFiles calls and close the files before align function is called. This does mean the temp files aren't deleted, so you'll also need to add temp file cleanup after the align call. I'm experimenting with eflomal for use with a Windows-based tool, so I might be able to make the necessary changes and add them to the codebase later.

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

No branches or pull requests

4 participants