Lifetime of a local reference

Test Bot onlinejudge95 at gmail.com
Wed Feb 27 03:20:32 EST 2019


Just to add on regarding file I/O. It would be more pythonic to use.

with open(path):
    do_stuff()

On Wed, Feb 27, 2019, 3:31 AM Marko Rauhamaa <marko at pacujo.net> 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.
>
>
> Marko
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list