Reputation: 8925
I'm running several scripts which are writing and reading from the same CSV file over a network share.
I'm getting intermittent OSError: [Errno 2] No such file or directory: 'filename.csv'
(every minute or two, with writing/reading every 10-30 seconds), but most of the time the file writing/reading works fine.
Is there any way to track which script has the file open when, and get some more details about the error? I.e. is file in use? Is it losing connection to the file server?
Ordinary operation (no error messages):
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
File open in another program (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
Misc error (not sure if this corresponds to a python error or not)
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
Would this show as an OSError 2?
Upvotes: 1
Views: 1602
Reputation: 8548
How a ftp share was created? how are organized 'open' files proceeding?
a) try to use 'with' according to pep 343.
if it not will work:
b) Try to make your own ftp share server with two methonds - read and
write. you can implement non-blocking reading algorithm.
Non-blocking algorithms are also safe for use in interrupt handlers: even though the preempted thread cannot be resumed, progress is still possible without it. In contrast, global data structures protected by mutual exclusion cannot safely be accessed in a handler, as the preempted thread may be the one holding the lock.
Upvotes: 0
Reputation: 400314
If you're on Windows, use Process Monitor to record all of the file operations done by Python.exe processes. If you're on Mac OS X or Solaris, use DTrace. If you're on Linux, use strace.
Any of those tools will give you a detailed listing of all of the system calls being made, along with their return codes, allowing you to narrow down what's failing and perhaps why.
Upvotes: 1
Reputation: 13510
As a workaround you can wrap the code with exception handling (try/except)
A real solution is more complicated - synchronizing the scripts. This is what I would do: Write a broker script which listens to commands (UDP or SimpleXMLRPCServer, for example). Other scripts communicate with it. All operations on the shared file are done via the broker.
Upvotes: 0