@@ -707,6 +707,9 @@ def getoutput(cmd):
707
707
708
708
709
709
class Popen (object ):
710
+
711
+ _child_created = False # Set here since __del__ checks it
712
+
710
713
def __init__ (self , args , bufsize = - 1 , executable = None ,
711
714
stdin = None , stdout = None , stderr = None ,
712
715
preexec_fn = None , close_fds = _PLATFORM_DEFAULT_CLOSE_FDS ,
@@ -717,7 +720,6 @@ def __init__(self, args, bufsize=-1, executable=None,
717
720
"""Create new Popen instance."""
718
721
_cleanup ()
719
722
720
- self ._child_created = False
721
723
self ._input = None
722
724
self ._communication_started = False
723
725
if bufsize is None :
@@ -859,11 +861,8 @@ def __exit__(self, type, value, traceback):
859
861
# Wait for the process to terminate, to avoid zombies.
860
862
self .wait ()
861
863
862
- def __del__ (self , _maxsize = sys .maxsize , _active = _active ):
863
- # If __init__ hasn't had a chance to execute (e.g. if it
864
- # was passed an undeclared keyword argument), we don't
865
- # have a _child_created attribute at all.
866
- if not getattr (self , '_child_created' , False ):
864
+ def __del__ (self , _maxsize = sys .maxsize ):
865
+ if not self ._child_created :
867
866
# We didn't get to successfully create a child process.
868
867
return
869
868
# In case the child hasn't been waited on, check if it's done.
@@ -1446,7 +1445,7 @@ def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
1446
1445
_WTERMSIG = os .WTERMSIG , _WIFEXITED = os .WIFEXITED ,
1447
1446
_WEXITSTATUS = os .WEXITSTATUS ):
1448
1447
# This method is called (indirectly) by __del__, so it cannot
1449
- # refer to anything outside of its local scope."""
1448
+ # refer to anything outside of its local scope.
1450
1449
if _WIFSIGNALED (sts ):
1451
1450
self .returncode = - _WTERMSIG (sts )
1452
1451
elif _WIFEXITED (sts ):
0 commit comments