No flock() in Windows!?

David LeBlanc whisper at oz.nospamnet
Mon May 7 12:29:50 EDT 2001

In article <7kzt29he.fsf at>, jdf at says...
> I'm fairly new to Python, and have been enjoying it.  
> In rewriting an old Perl script into Python, I was staggered to
> discover that there is simply no fcntl support at all on the Windows
> platform.  Such support is entirely platform-transparent in Perl, and
> I don't know how to work without it!
> How do you folks write cross-platform scripts that safely provide for
> advisory locking?
> I have searched the library docs and FAQ, I have searched the web and
> the Google Usenet archive.  If I missed something, pointers will be
> gladly followed.
Windows supports locking down to the byte level on files using the 
_locking() runtime library function. Don't know if or why it's not 
available in a python api.

>From MSDN:
The _locking function locks or unlocks nbytes bytes of the file specified 
by handle. Locking bytes in a file prevents access to those bytes by 
other processes. All locking or unlocking begins at the current position 
of the file pointer and proceeds for the next nbytes bytes. It is 
possible to lock bytes past end of file.

>From this description you might have to find the length of the file and 
lock that many from offset 0 to lock the whole file.

Dave LeBlanc

More information about the Python-list mailing list