Help: using msvcrt for file locking

Mark Hammond MarkH at
Mon Aug 27 00:06:15 CEST 2001

Sheila King wrote:

> On Sun, 26 Aug 2001 16:19:36 GMT, Sheila King <sheila at> wrote
> in comp.lang.python in article
> <pm5iotkp8d0q00kpqv31u1bmukqsp5fuh4 at>:
> :
> :I really don't see any way around file locking for the type of
> :application I'm trying to write. However, I guess after seeing all the
> :trouble with the msvcrt module, and how it doesn't even seem to allow
> :shared locking access to a file, that I will go ahead and use the
> :win32all extensions. I'm supposing that will allow better control?
> It appears, after a bit more research, that this will not work for all
> win32 platforms, anyway. Apparently unsupported on Win95/98/Me:
> (scroll down to just below where it says "requirements")

It appears that LockFileEx is designed specifically for files that use 
"overlapped IO".  Indeed, the "portalocker" recipe explicitly uses 
overlapped IO structures.

Try using LockFile - the MSDN documentation implies that it is supported 
on all Win32 platforms, and the error you get:

pywintypes.api_error: (120, 'LockFileEx', 'This function is only valid
in Win32 mode.')

implies you are running on Win9x.

A quick look at portalocker implies you will also want to drop all 
references to "_overlapped" - replace them with "None".


More information about the Python-list mailing list