[issue21351] refcounts not respected at process exit

Min RK report at bugs.python.org
Thu May 1 01:57:10 CEST 2014


Min RK added the comment:

Thanks for clarifying that there is indeed a reference cycle by way of the module, I hadn't realized that.

The gc blocking behavior is exactly why I brought up the issue. The real code where this causes a problem (rather than the toy example I attached) is in pyzmq, where destroying a Context object calls `zmq_term`, a GIL-less C call that will (and should) block until all associated sockets are closed. Deleting a socket closes it. Sockets hold a reference to the Context and not vice versa, which has ensured that the sockets are collected before the Context until Python 3.4. 

Does this mean it is no longer possible to express that one object should be cleaned up before another via references?

I think I will switch to adding an atexit call to set a flag that prevents any cleanup logic during the atexit process, since it does not appear to be possible to ensure deletion of one object before another in 3.4.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21351>
_______________________________________


More information about the Python-bugs-list mailing list