3 ms·
Does Python guarantee that finalizers are called at all? Most languages don't, I thought.
by chris_7 10y ago
Does Python guarantee that finalizers are called at all? Most languages don't, I thought.
- conistonwater 10y agoI know Haskell does: https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-ForeignPtr.html#v:newForeignPtr https://hackage.haskell.org/package/base-4.9.1.0/docs/Foreig... I'm not sure finalizers make sense without a guarantee they will eventually be called. But Haskell, for example, makes no guarantees about when it will be called, between the moment the last reference is lost and the moment the program exits. Python seems to, too: https://docs.python.org/3/library/weakref.html https://docs.python.org/3/library/weakref.html, "When the program exits, each remaining live finalizer is called unless its atexit attribute has been set to false. They are called in reverse order of creation."
- ambivalence 10y agoPEP 442 describes the situation with good detail, including how it was in Python 2 and how Python 3 improves on it: https://www.python.org/dev/peps/pep-0442/ https://www.python.org/dev/peps/pep-0442/