[Python-ideas] Atomic file.get(offset, length)

Terry Reedy tjreedy at udel.edu
Sat Jul 21 21:35:04 CEST 2012


On 7/21/2012 2:59 PM, Matt Chaput wrote:
> I wish Python binary file objects had an atomic seek-read method, so
> I wouldn't have to perform my own locking everywhere to prevent other
> threads from moving the file pointer between seek and read.

If you are reading a file from multiple threads, I suggest you write 
your own seek_and_read_with_locks function that does exactly what you 
need in one place. Or add a .readx method to a subclass.

 > Is this something that can be bubbled up from the underlying
 > platform? I think the Linux C equivalent is pread.

If there is a standard posix function that is not yet wrapped in os, you 
can propose its addition. But some research to see has widespread and 
actually standardized it is.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list