- I was wondering what happens during interpreter shutdown. I see you
have that listed as a open issue. How about simply shutting down the
finalization thread and not guaranteeing that finalizers are actually
ever run à la Java?
- Why not run all (Python) finalizers on the thread and not just ones
from cycles?
> https://mail.python.org/mailman/options/python-dev/benjamin%40python.org
- Why not run all (Python) finalizers on the thread and not just ones from cycles?
I don't know. People generally have expectations towards stuff being
finalized properly (especially when talking about files etc.).
Once the first implementation is devised, we will know more about
what's workable (perhaps we'll have to move _PyGC_Fini earlier in the
shutdown sequence? perhaps we'll want to switch back to serial mode
when shutting down?).
> - Why not run all (Python) finalizers on the thread and not just ones
> from cycles?
Because a lot of code probably expects them to be run as soon as the
last visible ref disappears.
Regards
Antoine.
On Fri, Sep 8, 2017, at 12:13, Antoine Pitrou wrote:
> On Fri, 08 Sep 2017 12:04:10 -0700
> Benjamin Peterson <benj...@python.org> wrote:
> > I like it overall.
> >
> > - I was wondering what happens during interpreter shutdown. I see you
> > have that listed as a open issue. How about simply shutting down the
> > finalization thread and not guaranteeing that finalizers are actually
> > ever run à la Java?
>
> I don't know. People generally have expectations towards stuff being
> finalized properly (especially when talking about files etc.).
> Once the first implementation is devised, we will know more about
> what's workable (perhaps we'll have to move _PyGC_Fini earlier in the
> shutdown sequence? perhaps we'll want to switch back to serial mode
> when shutting down?).
Okay, I'm curious to know what ends up happening here then.
>
> > - Why not run all (Python) finalizers on the thread and not just ones
> > from cycles?
>
> Because a lot of code probably expects them to be run as soon as the
> last visible ref disappears.
But this assumption is broken on PyPy and sometimes already by CPython,
so I don't feel very bad moving away from it.
PyPy just abandons everything when shutting down, instead of running
finalizers. See the last paragraph of :
http://doc.pypy.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies
So that might be a useful source of experience.
On another note, I'm going to be that annoying person who suggests
massively extending the scope of your proposal. Feel free to throw
things at me or whatever.
Would it make sense to also move signal handlers to run in this
thread? Those are the other major source of nasty re-entrancy
problems.
-n
--
Nathaniel J. Smith -- https://vorpus.org
On Fri, Sep 8, 2017, at 12:24, Larry Hastings wrote:On 09/08/2017 12:04 PM, Benjamin Peterson wrote:- Why not run all (Python) finalizers on the thread and not just ones from cycles?Two reasons: 1. Because some code relies on the finalizer being called on the thread where the last reference is dropped. This is usually the same thread where the object was created. Some irritating third-party libraries make demands on callers, e.g. "you can only interact with / destroy X objects on your 'main thread'". This is often true of windowing / GUI libraries. (For example, I believe this was true of Direct3D, at least as of D3D8; it was also often true of Win32 USER objects.)Is the requirement that the construction and destruction be literally on the same thread or merely non-concurrent? The GIL would provide the latter.
On Fri, 8 Sep 2017 12:40:34 -0700
Nathaniel Smith <n...@pobox.com> wrote:
>
> PyPy just abandons everything when shutting down, instead of running
> finalizers. See the last paragraph of :
> http://doc.pypy.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies
>
> So that might be a useful source of experience.
CPython can be embedded in applications, though, and that is why we try
to be a bit more thorough during the interpreter cleanup phase.