This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Eric Cousineau
Recipients Eric Cousineau, docs@python
Date 2017-12-19.16:29:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1513700999.05.0.213398074469.issue32377@psf.upfronthosting.co.za>
In-reply-to
Content
Due to how `PyObject_CallFinalizer` is written in python3, `__del__` will only *ever* be called once.

In my use case, I am experimenting with a feature in `pybind11` to prevent slicing with Python class instances that inherit from pybind11-C++ base classes, which involves detecting when an instance loses all reference in Python (`Py_REFCNT(...) == 0`) but still has reference in C++ (`shared_ptr::count() > 0`), and reviving the Python portion when this situation happens.

In python2, I could do this without a hitch, as a resurrected object could have its `__del__` method called multiple times (through `tp_dealloc` I believe?). But in python3, the object is marked with `_PyGC_SET_FINALIZED(...)`, thus preventing `__del__` from being called again.

It'd be nice to either (a) somehow allow `__del__` to be called naturally without too much fuss or, at the least, (b) have this reflected in the documentation:
https://docs.python.org/3/reference/datamodel.html#object.__del__

See attached `revive_test`. Example execution:

```
$ python2 ./revive_test.py 
Revive
Destroy
[ Done ]

$ python3 ./revive_test.py 
Revive
[ Done ]
```
History
Date User Action Args
2017-12-19 16:29:59Eric Cousineausetrecipients: + Eric Cousineau, docs@python
2017-12-19 16:29:59Eric Cousineausetmessageid: <1513700999.05.0.213398074469.issue32377@psf.upfronthosting.co.za>
2017-12-19 16:29:59Eric Cousineaulinkissue32377 messages
2017-12-19 16:29:58Eric Cousineaucreate