简体   繁体   English

文件已被Python调试器锁定

[英]File is locked by Python debugger

I have a problem with understanding a strange file locking behavior in Python Debugger. 我在理解Python Debugger中奇怪的文件锁定行为时遇到问题。

I have a 2TB image file, which my script reads. 我有一个2TB映像文件,我的脚本会读取该文件。 Everything works perfect, until I want to read the same file with a different hex editor. 一切正常,直到我想使用其他十六进制编辑器读取相同文件。 If the file is opened in hex editor before I start my script, everything is fine. 如果在启动脚本之前在十六进制编辑器中打开了文件,则一切正常。 If I try to open the file during script paused at breakpoint, my system almost hangs and becomes very slow. 如果我在脚本在断点处暂停期间尝试打开文件,我的系统几乎会挂起并变得非常慢。 I normally can kill Pyhon and hex editor from terminal, but it is very slow and takes up to 10 minutes. 我通常可以从终端杀死Pyhon和十六进制编辑器,但是它非常慢,最多需要10分钟。

The same problem apperares AFTER I stop the script and even extensively kill all Python instances. 在我停止脚本并甚至广泛杀死所有Python实例之后,同样的问题也解决了。 The disk, where this image is situated is remained locked and it's not possible to unmount it (only with diskutil force command), system hangs if I try to open the file anywhere else. 该映像所在的磁盘保持锁定状态,无法卸载(仅使用diskutil force命令),如果我尝试在其他位置打开文件,系统将挂起。

Also I can't start scripts one after another, next scripts just stops working and hangs my system. 另外,我无法一个接一个地启动脚本,下一个脚本会停止工作并挂起我的系统。

I have to wait up to 10 minutes to be able to work with the file again. 我最多需要等待10分钟才能再次使用该文件。

I tried to find the process which locks the file with "sudo lsof +D" command but it doesn't list anything. 我试图找到使用“ sudo lsof + D”命令锁定文件的过程,但未列出任何内容。

Here are some more details: — My system is Mac Os X 10.9. 以下是更多详细信息:—我的系统是Mac Os X 10.9。 Python is 3.4. Python是3.4。 I use Eclipse with Pydev to develop the script. 我将Eclipse与Pydev一起使用来开发脚本。 — I use open('image.dmg', mode='rb') command to open the file in python and close()to close it. —我使用open('image.dmg',mode ='rb')命令在python中打开文件,然后使用close()将其关闭。 — The file is a 2TB disk image on external ExFat formatted drive. —该文件是外部ExFat格式化驱动器上的2TB磁盘映像。 Other files don't have such problems. 其他文件没有此类问题。 File is write-protected in Finder settings. 文件在Finder设置中受写保护。

Can anyone direct me in a proper direction to locate the source of this problem? 谁能指导我正确的方向以找到问题的根源?

I never worked with Mac OS but I could imagine this: 我从未使用过Mac OS,但可以想象得到:

  • Maybe Python locks the file on open and the hex-editor is failing if you try to open it afterwards. 也许Python将文件锁定在打开状态,并且如果您随后尝试打开它,则十六进制编辑器将失败。
  • The system hangs and get slow (even after killing all processes) -> I think thats some kind of caching which fill up your memory till your computer starts using the harddisk as memory (and turns really slow) 系统挂起并变慢(即使在杀死所有进程之后)->我认为这是某种缓存,它将填满您的内存,直到您的计算机开始将硬盘用作内存(并且变慢)

I think you should try to find out how files get open with python on Mac OS (if there is some kind of lock) and you should take care that this large file never get stored complete in memory (there are different methods how to read large files in chunks). 我认为您应该尝试找出如何在Mac OS上使用python打开文件(如果有某种锁的话),并且应该注意不要将此大文件完整地存储在内存中(有多种读取大文件的方法)文件)。

Greetings Kuishi 问候Ku石

PS: I apologize for my English. PS:我为我的英语表示歉意。 It isnt my native language. 这不是我的母语。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM