我正在运行几个脚本,这些脚本通过网络共享从同一个 CSV 文件中写入和读取。
我变得断断续续OSError: [Errno 2] No such file or directory: 'filename.csv'
(每分钟或每两分钟,每 10-30 秒写入/读取一次),但大多数时候文件写入/读取工作正常。
有什么方法可以跟踪哪个脚本在何时打开文件,并获取有关错误的更多详细信息?即文件在使用中?它是否失去与文件服务器的连接?
使用进程监视器:
普通操作(无错误信息):
2:33:52.4823608 PM python.exe 2668 IRP_MJ_QUERY_VOLUME_INFORMATION filename.csv SUCCESS Type: QueryDeviceInformationVolume, DeviceType: Disk, Characteristics: Remote
2:33:52.4823848 PM python.exe 2668 IRP_MJ_QUERY_VOLUME_INFORMATION filename.csv SUCCESS Type: QueryDeviceInformationVolume, DeviceType: Disk, Characteristics: Remote
2:33:52.4824062 PM python.exe 2668 IRP_MJ_QUERY_VOLUME_INFORMATION filename.csv BUFFER OVERFLOW Type: QueryInformationVolume, VolumeCreationTime: 1/1/1601 8:00:00 AM, VolumeSerialNumber: D020-FD78, SupportsObjects: False, VolumeLabel: DAT`
2:33:52.4827061 PM python.exe 2668 IRP_MJ_QUERY_INFORMATION filename.csv BUFFER OVERFLOW Type: QueryAllInformationFile, CreationTime: 4/24/2012 2:36:07 PM, LastAccessTime: 4/24/2012 2:36:07 PM, LastWriteTime: 4/24/2012 2:36:07 PM, ChangeTime: 4/24/2012 2:36:07 PM, FileAttributes: A, AllocationSize: 1,048,576, EndOfFile: 118,342, NumberOfLinks: 1, DeletePending: False, Directory: False, IndexNumber: 0x45060de, EaSize: 0, Access: None, Position: 0, Mode: , AlignmentRequirement: Byte
2:33:52.4837725 PM python.exe 2668 FASTIO_QUERY_INFORMATION filename.csv FAST IO DISALLOWED Type: QueryStandardInformationFile
2:33:52.4837820 PM python.exe 2668 IRP_MJ_QUERY_INFORMATION filename.csv SUCCESS Type: QueryStandardInformationFile, AllocationSize: 1,048,576, EndOfFile: 118,342, NumberOfLinks: 1, DeletePending: False, Directory: False
2:33:52.4841324 PM python.exe 2668 FASTIO_QUERY_INFORMATION filename.csv FAST IO DISALLOWED Type: QueryStandardInformationFile
2:33:52.4841458 PM python.exe 2668 IRP_MJ_QUERY_INFORMATION filename.csv SUCCESS Type: QueryStandardInformationFile, AllocationSize: 1,048,576, EndOfFile: 118,342, NumberOfLinks: 1, DeletePending: False, Directory: False
2:33:52.4844948 PM python.exe 2668 IRP_MJ_READ filename.csv SUCCESS Offset: 117,318, Length: 1,024
2:33:52.4857179 PM python.exe 2668 IRP_MJ_READ filename.csv END OF FILE Offset: 118,342, Length: 4,096
2:33:52.4862472 PM python.exe 2668 FASTIO_QUERY_INFORMATION filename.csv FAST IO DISALLOWED Type: QueryStandardInformationFile
2:33:52.4862564 PM python.exe 2668 IRP_MJ_QUERY_INFORMATION filename.csv SUCCESS Type: QueryStandardInformationFile, AllocationSize: 1,048,576, EndOfFile: 118,342, NumberOfLinks: 1, DeletePending: False, Directory: False
2:33:52.4867251 PM python.exe 2668 IRP_MJ_READ filename.csv SUCCESS Offset: 116,294, Length: 1,024
2:33:52.4873473 PM python.exe 2668 IRP_MJ_READ filename.csv SUCCESS Offset: 117,318, Length: 512
2:33:52.4878825 PM python.exe 2668 FASTIO_QUERY_INFORMATION filename.csv FAST IO DISALLOWED Type: QueryStandardInformationFile
2:33:52.4878917 PM python.exe 2668 IRP_MJ_QUERY_INFORMATION filename.csv SUCCESS Type: QueryStandardInformationFile, AllocationSize: 1,048,576, EndOfFile: 118,342, NumberOfLinks: 1, DeletePending: False, Directory: False
2:33:52.4882153 PM python.exe 2668 IRP_MJ_READ filename.csv SUCCESS Offset: 115,270, Length: 1,024
2:33:52.4889601 PM python.exe 2668 IRP_MJ_READ filename.csv SUCCESS Offset: 116,294, Length: 512
2:33:52.4895164 PM python.exe 2668 IRP_MJ_CLEANUP filename.csv SUCCESS
2:33:52.4895513 PM python.exe 2668 IRP_MJ_CLOSE filename.csv SUCCESS
在另一个程序中打开文件(Errno 13 - Permission Denied):
1:12:42.0840918 PM python.exe 5772 IRP_MJ_CREATE filename.csv SHARING VIOLATION Desired Access: Generic Write, Read Attributes, Disposition: OpenIf, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
杂项错误(不确定这是否对应于 python 错误)
2:57:59.9371101 PM python.exe 3584 IRP_MJ_CREATE filename.log BAD NETWORK PATH Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a
这会显示为 OSError 2 吗?