fcntl.flock() not working when called from a function

jepler at unpythonic.net jepler at unpythonic.net
Fri Nov 4 14:42:01 EST 2005


The file you open() may be closed as soon as it is no longer possible to refer to it.

So in the first case, because the top-level variable 'f' continues to refer to the opened
file, the file may not be closed.

In the second case, no variable refers to the opened file after lock() returns, so Python is
free to close the file at any time.  In fact, Python happens to close the function exactly
when lock() returs.

If you want an open file descriptor that is not automatically closed, use os.open().  Or,
store the file descriptor somewhere so you can later close() or unlock it at an
appropriate time.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051104/ca9d27ef/attachment.sig>


More information about the Python-list mailing list