TL;DR:从使用tox
创建的pypy
环境中运行python setup.py develop --uninstall
会导致异常:error: [Error 32] The process cannot access the file because it is being used by another process: c:\users\shach\code\pydocstyle\.tox\pypy\site-packages\funniest.egg-link
。在
大家好
我有一组针对python包的集成测试,它们执行以下操作:
python setup.py develop
(使用subprocess.check_call
)测试正在由tox
运行。在python版本27
、33
、34
、35
和36
上一切正常,但代码在pypy
上失败。在
我不打算在这里包括setup.py
和项目文件,您可以假设它们很好。我用显示的最小包here复制了它,它可以工作(失败吗?)都一样。在
为了重现,我创建了一个运行以下内容的python脚本:
import shlex
import subprocess
subprocess.check_call(shlex.split('python setup.py develop'))
print('----------')
subprocess.check_call(shlex.split('python setup.py develop --uninstall'))
使用系统上安装的常规pypy
运行文件可以正常工作:
但是当我从tox
环境中为pypy
运行它时:
C:\Users\shach\code\bla\funniest>tox
GLOB sdist-make: C:\Users\shach\code\bla\funniest\setup.py
pypy inst-nodeps: C:\Users\shach\code\bla\funniest\.tox\dist\funniest-0.1.zip
pypy installed: cffi==1.10.1,funniest==0.1,greenlet==0.4.12,readline==6.2.4.1
pypy runtests: PYTHONHASHSEED='122'
pypy runtests: commands[0] | python test.py
running develop
running egg_info
writing funniest.egg-info\PKG-INFO
writing dependency_links to funniest.egg-info\dependency_links.txt
writing top-level names to funniest.egg-info\top_level.txt
reading manifest file 'funniest.egg-info\SOURCES.txt'
writing manifest file 'funniest.egg-info\SOURCES.txt'
running build_ext
Creating c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
funniest 0.1 is already the active version in easy-install.pth
Installed c:\users\shach\code\bla\funniest
Processing dependencies for funniest==0.1
Finished processing dependencies for funniest==0.1
----------
running develop
Removing c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
error: [Error 32] The process cannot access the file because it is being used by another process: c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link
Traceback (most recent call last):
File "test.py", line 6, in <module>
subprocess.check_call(shlex.split('python setup.py develop --uninstall'))
File "C:\Python\pypy\lib-python\2.7\subprocess.py", line 186, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['python', 'setup.py', 'develop', '--uninstall']' returned non-zero exit status 1
ERROR: InvocationError: 'C:\\Users\\shach\\code\\bla\\funniest\\.tox\\pypy\\bin\\python.EXE test.py'
___________________________________ summary ___________________________________
ERROR: pypy: commands failed
C:\Users\shach\code\bla\funniest>
以下是我用来复制的tox.ini
:
[tox]
envlist = pypy
[testenv]
commands=python test.py
我确定了我对这个目录有读/写权限,现在我有点不知所措了。在
它在linux上运行得很好。可能是因为您可以删除正在使用的文件(inodes
,等等):^)
更新1:
我想问题可能在于develop
和{egg-link
),所以我手动运行了它:
C:\Users\shach\code\bla\funniest>.tox\pypy\bin\activate.bat
(pypy) C:\Users\shach\code\bla\funniest>pypy setup.py develop
running develop
running egg_info
writing funniest.egg-info\PKG-INFO
writing dependency_links to funniest.egg-info\dependency_links.txt
writing top-level names to funniest.egg-info\top_level.txt
reading manifest file 'funniest.egg-info\SOURCES.txt'
writing manifest file 'funniest.egg-info\SOURCES.txt'
running build_ext
Creating c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
funniest 0.1 is already the active version in easy-install.pth
Installed c:\users\shach\code\bla\funniest
Processing dependencies for funniest==0.1
Finished processing dependencies for funniest==0.1
(pypy) C:\Users\shach\code\bla\funniest>pypy setup.py develop --uninstall
running develop
Removing c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
error: [Error 32] The process cannot access the file because it is being used by another process: c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link
(pypy) C:\Users\shach\code\bla\funniest>
仍然失败:(
请指教!在
沙查尔。在
更新2:
我尝试过使用Sysinternal的 更新3: 在关闭CMD并打开一个新命令后仍会发生。在 更新4: 重启机器不能解决这个问题!什么?在Process Explorer
和nada检查是否有进程保存该文件。{{cd26>,然后在
TL;DR:不要直接使用
setup.py
,使用pip install -e .
。在问题似乎出在windows上的
setuptools
。所发生的情况是,egg-link
文件在被删除之前只打开和关闭了几行,而windows无法处理这一点。在不知何故,
pip
确实能处理这种情况,我会在有更多信息时更新。在我在setuptools中打开了一个issue。在
从描述来看,似乎在
pypy setup.py develop uninstall
运行的某个地方,一个文件或目录正处于打开状态,这会阻止在windows上删除它。您可以尝试使用“-X track resources”参数(pypy -X track-resources setup.py develop uninstall
)运行pypy,该参数应通知您是否在关闭资源之前释放了包含资源的对象。有时,扫描s - open(path).read()
这样的代码就足以找到问题所在,该代码将泄漏文件描述符,直到垃圾回收器运行、注意到ghost对象并将其删除。代码应该使用上下文管理器;with open(path) as fid: s = fid.read()
相关问题 更多 >
编程相关推荐