Message198230
| Author |
terry.reedy |
| Recipients |
Arfrever, chortos, gvanrossum, petri.lehtinen, pitrou, python-dev, r.david.murray, serhiy.storchaka, terry.reedy, vstinner |
| Date |
2013年09月21日.23:02:07 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1379804527.99.0.805331581279.issue12085@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
The message problem can arise during exit if __del__ depends an any attribute of any object. It is hard to imagine a __del__ method that does not. Any __del__ method, including that of Popen, could handle AttributeErrors by wrapping the whole body in
try:
<body>
except AttributeError:
pass
The is essentially what is done by the code that calls __del__, except that 'pass' is replaced by "print(message, file=sys.stderr)".
If we patch Popen at all, I think this try:except should be the fix, not a class attribute.
To explain what I meant by the class attribute hack being tricky, consider the original version of Popen.__del__, minus the comments.
def __del__(self, _maxsize=sys.maxsize, _active=_active):
if not self._child_created:
return
self._internal_poll(_deadstate=_maxsize)
if self.returncode is None and _active is not None:
_active.append(self)
Since self._internal_poll is an instance method, it is not a problem. But what about the self.returncode data attribute? Should we also add a class 'returncode' attribute? If so, what should be its value? None? or object()? Or is it guaranteed that when _child_created is set true, returncode will be defined, so that a class attribute is not needed?
I don't know the answers to these questions. Popen.__init__ is about 130 lines and self._child_created is set to True in two other methods. I did not look where returncode is set, but it is not near the spots where _child_created is set True. |
|