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

Attachment: pgpv7jRCugW7o.pgp
Description: PGP signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to