Skip to content

Commit

Permalink
check process status for non-child process
Browse files Browse the repository at this point in the history
  • Loading branch information
masteret committed Mar 20, 2017
1 parent 8f1ba73 commit 420f657
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions ptyprocess/ptyprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,25 @@ def isalive(self):
except OSError as e:
# No child processes
if e.errno == errno.ECHILD:
raise PtyProcessError('isalive() encountered condition ' +
'where "terminated" is 0, but there was no child ' +
'process. Did someone else call waitpid() ' +
'on our process?')
try:
os.kill(self.pid, 0)
except OSError as err:
if err.errno == errno.ESRCH:
# No such process
raise PtyProcessError('isalive() encountered condition ' +
'where "terminated" is 0, but there was no child ' +
'process. Did someone else call waitpid() ' +
'on our process?')
elif err.errno == errno.EPERM:
# Process deny access
raise PtyProcessError('isalive() encountered condition ' +
'where the child process deny access')
else:
# Other possible error
raise err
else:
# Process exists not as child
pid, status = 0, 0
else:
raise

Expand All @@ -717,10 +732,25 @@ def isalive(self):
except OSError as e: # pragma: no cover
# This should never happen...
if e.errno == errno.ECHILD:
raise PtyProcessError('isalive() encountered condition ' +
'that should never happen. There was no child ' +
'process. Did someone else call waitpid() ' +
'on our process?')
try:
os.kill(self.pid, 0)
except OSError as err:
if err.errno == errno.ESRCH:
# No such process
raise PtyProcessError('isalive() encountered condition ' +
'where "terminated" is 0, but there was no child ' +
'process. Did someone else call waitpid() ' +
'on our process?')
elif err.errno == errno.EPERM:
# Process deny access
raise PtyProcessError('isalive() encountered condition ' +
'where the child process deny access')
else:
# Other possible error
raise err
else:
# Process exists not as child
pid, status = 0, 0
else:
raise

Expand Down

0 comments on commit 420f657

Please sign in to comment.