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

Temporary files: Permission denied #2547

Closed
felixdivo opened this issue Jul 31, 2018 · 4 comments
Closed

Temporary files: Permission denied #2547

felixdivo opened this issue Jul 31, 2018 · 4 comments

Comments

@felixdivo
Copy link

I am trying to write some temporary files using Python's NamedTemporaryFile and alike, and get errors:

IOError: [Errno 13] Permission denied: 'c:\\projects\\python-can\\test\\__tmpdir__\\tmpj6uyhy.asc'

This occurs in the python-can repo, for example right here. The .appveyor.yml file looks like this:

environment:
  matrix:

    # For Python versions available on Appveyor, see
    # http://www.appveyor.com/docs/installed-software#python

    - PYTHON: "C:\\Python27"
    - PYTHON: "C:\\Python34"
    - PYTHON: "C:\\Python35"
    - PYTHON: "C:\\Python36"
    - PYTHON: "C:\\Python27-x64"
    - PYTHON: "C:\\Python34-x64"
    - PYTHON: "C:\\Python35-x64"
    - PYTHON: "C:\\Python36-x64"

    # Python 3.3 has reached EOL

install:
  # Prepend Python installation to PATH
  - set PATH=%PYTHON_INSTALL%;%PATH%

  # Prepend Python scripts to PATH (e.g. py.test)
  - set PATH=%PYTHON_INSTALL%\\Scripts;%PATH%

  # We need to install the python-can library itself
  - "python -m pip install .[test,neovi]"

build: off

before_test:
  # see: https://help.appveyor.com/discussions/problems/938-getting-permission-denied-errors-when-trying-to-make-a-temp-directory
  # TMPDIR is used by Python to detect the temporary directory: https://docs.python.org/3/library/tempfile.html#tempfile.tempdir
  - set TMPDIR=%APPVEYOR_BUILD_FOLDER%\test\__tmpdir__
  - mkdir %TMPDIR%
  - icacls %TMPDIR% /inheritance:r /grant Everyone:(OI)(CI)F

test_script:
  - "pytest"
  - "codecov"

after_test:
  - rmdir /S /Q %TMPDIR%

Note: The before_test section was added in hope to solve the problem, but didn't help.

@IlyaFinkelshteyn
Copy link
Contributor

I have no exact solution, but let me share my investigation, maybe it will bring some ideas.

I cloned your repo and was able to reproduce the problem. Then connected to build worker with RDP and was able to reproduce it manually in command line (was needed to set TMPDIR before). Then installed Process monitor and monitored access to everything in C:\projects\python-can\test\__tmpdir__ and I see that with both 2 files from pytest error (and only with them), SHARING VIOLATION error occurred (see pic).

2018-08-01_07h47_01

Can it be some concurrency issue? I have no knowledge about pytest, but maybe you can disable some tests concurrency? Also what if you add some retry logic?

And finally, does it work when being executed the same way on local Windows machine?

@felixdivo
Copy link
Author

Thanks for your investigation!

Can it be some concurrency issue?

I doubt it, since Pytest without any plugins does not use concurrent testing AFAIK.

Also what if you add some retry logic?

I could add some retry logic, although that would only be a solution for debugging the problem.

And is it the same way on a local Windows machine?

I will check.

@felixdivo
Copy link
Author

Okay, I solved the problem. Actually, it was not a problem about permissions at all. ☹️

It was a problem of how tempfile.NamedTemporaryFile works on Windows. This now works:

with tempfile.NamedTemporaryFile(suffix=extension, delete=False) as my_file:
    filename = my_file.name
with can.Logger(filename) as writer:
    self.assertIsInstance(writer, klass)
# delete "manually" afterwards

@IlyaFinkelshteyn
Copy link
Contributor

Great, thanks for the update!

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

2 participants