Message308660
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 ]
``` |
|
Date |
User |
Action |
Args |
2017-12-19 16:29:59 | Eric Cousineau | set | recipients:
+ Eric Cousineau, docs@python |
2017-12-19 16:29:59 | Eric Cousineau | set | messageid: <1513700999.05.0.213398074469.issue32377@psf.upfronthosting.co.za> |
2017-12-19 16:29:59 | Eric Cousineau | link | issue32377 messages |
2017-12-19 16:29:58 | Eric Cousineau | create | |
|