Issue
|
def read(self): |
|
data, bad_format = None, False |
|
try: |
|
data = json.loads(self.file.read_text()) |
|
logging.debug("got {} from %s".format(self.msg), *self.msg_args) |
|
return data |
|
except ValueError: |
|
bad_format = True |
|
except Exception: # noqa |
|
pass |
|
if bad_format: |
|
self.remove() |
|
return None |
When the file is opened for writing in another process, the JSON content can't be parsed, then the file will be removed. However, on Windows the removal will fail since the file is occupied by anther process.
Environment
Provide at least:
Output of the virtual environment creation
Make sure to run the creation with -vvv --with-traceback:
Traceback (most recent call last):
File "C:\Users\runneradmin\.virtualenvs\pipenv-6Kr0DpZ2\lib\site-packages\virtualenv\seed\embed\via_app_data\via_app_data.py", line 94, in _get
do_periodic_update=self.periodic_update,
File "C:\Users\runneradmin\.virtualenvs\pipenv-6Kr0DpZ2\lib\site-packages\virtualenv\seed\wheels\acquire.py", line 25, in get_wheel
wheel = from_bundle(distribution, version, for_py_version, search_dirs, app_data, do_periodic_update)
File "C:\Users\runneradmin\.virtualenvs\pipenv-6Kr0DpZ2\lib\site-packages\virtualenv\seed\wheels\bundle.py", line 20, in from_bundle
wheel = periodic_update(distribution, for_py_version, wheel, search_dirs, app_data, do_periodic_update)
File "C:\Users\runneradmin\.virtualenvs\pipenv-6Kr0DpZ2\lib\site-packages\virtualenv\seed\wheels\periodic_update.py", line 41, in periodic_update
handle_auto_update(distribution, for_py_version, wheel, search_dirs, app_data)
File "C:\Users\runneradmin\.virtualenvs\pipenv-6Kr0DpZ2\lib\site-packages\virtualenv\seed\wheels\periodic_update.py", line 62, in handle_auto_update
u_log = UpdateLog.from_dict(embed_update_log.read())
File "C:\Users\runneradmin\.virtualenvs\pipenv-6Kr0DpZ2\lib\site-packages\virtualenv\app_data\via_disk_folder.py", line 140, in read
self.remove()
File "C:\Users\runneradmin\.virtualenvs\pipenv-6Kr0DpZ2\lib\site-packages\virtualenv\app_data\via_disk_folder.py", line 144, in remove
self.file.unlink()
File "C:\hostedtoolcache\windows\Python\3.6.8\x64\lib\pathlib.py", line 1284, in unlink
self._accessor.unlink(self)
File "C:\hostedtoolcache\windows\Python\3.6.8\x64\lib\pathlib.py", line 387, in wrapped
return strfunc(str(pathobj), *args)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\runneradmin\\AppData\\Local\\pypa\\virtualenv\\wheel\\3.8\\embed\\1\\wheel.json'
PermissionError(13, 'The process cannot access the file because it is being used by another process')
RuntimeError: seed failed due to failing to download wheels wheel
To fix the issue, I prefer to change the writing into atomic, that is, before the writing is done, the content should be kept.
If that is an acceptable approach I can send a PR.
Issue
virtualenv/src/virtualenv/app_data/via_disk_folder.py
Lines 129 to 141 in 0cd009b
When the file is opened for writing in another process, the JSON content can't be parsed, then the file will be removed. However, on Windows the removal will fail since the file is occupied by anther process.
Environment
Provide at least:
OS: Windows 10
pip listof the host python wherevirtualenvis installed:Output of the virtual environment creation
Make sure to run the creation with
-vvv --with-traceback:To fix the issue, I prefer to change the writing into atomic, that is, before the writing is done, the content should be kept.
If that is an acceptable approach I can send a PR.