msvcrt, open_osfhandle, locking
Fredrik Lundh
effbot at telia.com
Fri Feb 25 05:54:50 EST 2000
Roger Baklund (shouldn't that be Backlund? ;-):
> >Oops - meant "locking function in msvcrt module"
>
> Hmmm. Do you have an example? I can't get it to work.
>
> The documentation says: "locking (fd, mode, nbytes)
> Lock part of a file based on a file descriptor from the C
> runtime. Raises IOError on failure. "
> and for open_osfhandle: "open_osfhandle (handle, flags)
> Create a C runtime file descriptor from the file handle handle."
forget those docstrings. they may be technically
correct, but they sure are confusing as hell ;-)
here's an extract from the eff-bot guide (see
msvcrt-example-3.py for the full story):
...
_LK_UNLCK = 0 # unlock the file region
_LK_LOCK = 1 # lock the file region
_LK_NBLCK = 2 # non-blocking lock
_LK_RLCK = 3 # lock for writing
_LK_NBRLCK = 4 # non-blocking lock for writing
...
file = open(FILE, "r+")
# look from current position (0) to end of file
msvcrt.locking(file.fileno(), _LK_LOCK, os.path.getsize(FILE))
...
hope this helps!
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list