Lifetime of a local reference

Tim Daneliuk info at tundraware.com
Tue Feb 26 17:08:05 EST 2019


On 2/26/19 3:54 PM, Marko Rauhamaa wrote:
> Consider this function:
> 
>     def fun():
>         f = open("lock")
>         flock.flock(f, fcntl.LOCK_EX)
>         do_stuff()
>         sys.exit(0)
> 
> Question: can a compliant Python implementation close f (and,
> consequently, release the file lock) before/while do_stuff() is
> executed?
> 
> I couldn't find an immediate answer in the documentation.


Not quite sure what you are asking.  Are you asking if the file handle
can be closed before (or concurrently if do_stuff() is a thread) and
do_stuff() can continue to make use of the handle?



More information about the Python-list mailing list