Terry J. Reedy added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue12085>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com