weakref.finalize always executes during the ordinary Python flow, IIUC --
e.g., it happens before the interpreter is stopping. I guess it does still
have the "arbitrary thread" limitation -- which is a good point, I may have
some code bugs of my own to fix. But it's a huge difference in terms of
predictability of the interpreter state, and in particular both the issues
around deleted modules and the ones around threading no longer working
don't apply to it.

atexit is a pretty corner-case thing -- I agree that it shouldn't be the
common thing at all, and the recommendation should be specifically for
those use cases where it makes sense. FD's are a classic thing to close
with weakref.finalize.

On Thu, Jan 2, 2020 at 7:47 AM Andrew Svetlov <andrew.svet...@gmail.com>
wrote:

> I would say that the "recommended" weakref.finalize() shares very many
> limitations of __del__(), that's why hard to buy it.
> atexit.register() is not a common thing, the recommendation of using
> atexit for file descriptor closing *in general* looks weird, while it
> can be a good solution in some particular case.
>
> On Thu, Jan 2, 2020 at 1:05 PM Armin Rigo <armin.r...@gmail.com> wrote:
> >
> > Hi,
> >
> > On Thu, 2 Jan 2020 at 03:59, Yonatan Zunger <zun...@humu.com> wrote:
> > > It is possible (though not recommended!) for the __del__() method to
> postpone destruction of the instance by creating a new reference to it.
> This is called object resurrection. It is implementation-dependent whether
> __del__() is called a second time when a resurrected object is about to be
> destroyed; the current CPython implementation only calls it once.
> >
> > "...in most cases."
> >
> >
> > Armin Rigo
>
>
>
> --
> Thanks,
> Andrew Svetlov
>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/FIM4PII72PCUZ7WVZBGCPHRNXYRH7WIX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to