Syntax: os.wifexited(status) Parameter: status: This parameter takes process status code (an integer value) as returned by os.system(), os.wait() or os.waitpid() method. Return type: This method returns True if the process exited using exit(2) system call else returns False.
os.wifexited() example 1
def poll(self, flag=os.WNOHANG): if self.returncode is None: while True: try: pid, sts = os.waitpid(self.pid, flag) except os.error as e: if e.errno == errno.EINTR: continue # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None else: break if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) else: assert os.wifexited(sts) self.returncode = os.WEXITSTATUS(sts) return self.returncode
os.wifexited() example 2
def poll(self, flag=os.WNOHANG): if self.returncode is None: while True: try: pid, sts = os.waitpid(self.pid, flag) except os.error as e: if e.errno == errno.EINTR: continue # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None else: break if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) else: assert os.wifexited(sts) self.returncode = os.WEXITSTATUS(sts) return self.returncode
os.wifexited() example 3
def platformProcessEvent(self, status): if os.wifexited(status): tid = self.getMeta("ThreadId", -1) if tid != self.getPid(): # Set the selected thread ID to the pid cause # the old one’s invalid if tid in self.pthreads: self.pthreads.remove(tid) self.setMeta("ThreadId", self.getPid()) self._fireExitThread(tid, os.WEXITSTATUS(status)) else: self._fireExit(os.WEXITSTATUS(status)) elif os.WIFSIGNALED(status): self.setMeta("ExitCode", os.WTERMSIG(status)) self.fireNotifiers(vtrace.NOTIFY_EXIT) elif os.WIFSTOPPED(status): sig = os.WSTOPSIG(status) self.handlePosixSignal(sig) else: print "OMG WTF JUST HAPPENED??!?11/!?1?>!"
os.wifexited() example 4
def poll(self, flag=os.WNOHANG): if self.returncode is None: while True: try: pid, sts = os.waitpid(self.pid, flag) except os.error as e: if e.errno == errno.EINTR: continue # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None else: break if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) else: assert os.wifexited(sts) self.returncode = os.WEXITSTATUS(sts) return self.returncode
os.wifexited() example 5
def signalStatus(self, signal): """ Construct a status from the given signal. @type signal: L{int} between 0 and 255 inclusive. @param signal: The signal number which the status will represent. @rtype: L{int} @return: A status integer for the given signal. """ # /* If WIFSIGNALED(STATUS), the terminating signal. */ # #define __WTERMSIG(status) ((status) & 0x7f) # /* Nonzero if STATUS indicates termination by a signal. */ # #define __WIFSIGNALED(status) # (((signed char) (((status) & 0x7f) + 1) >> 1) > 0) status = signal # Sanity check self.assertTrue(os.WIFSIGNALED(status)) self.assertEqual(os.WTERMSIG(status), signal) self.assertFalse(os.wifexited(status)) return status
os.wifexited() example 6
def exitStatus(self, code): """ Construct a status from the given exit code. @type code: L{int} between 0 and 255 inclusive. @param code: The exit status which the code will represent. @rtype: L{int} @return: A status integer for the given exit code. """ # /* Macros for constructing status values. */ # #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) status = (code << 8) | 0 # Sanity check self.assertTrue(os.wifexited(status)) self.assertEqual(os.WEXITSTATUS(status), code) self.assertFalse(os.WIFSIGNALED(status)) return status
os.wifexited() example 7
def GetExitStatus(exit_code): """Returns the argument to exit(), or -1 if exit() wasn’t called. Args: exit_code: the result value of os.system(command). """ if os.name == ’nt’: # On Windows, os.WEXITSTATUS() doesn’t work and os.system() returns # the argument to exit() directly. return exit_code else: # On Unix, os.WEXITSTATUS() must be used to extract the exit status # from the result of os.system(). if os.wifexited(exit_code): return os.WEXITSTATUS(exit_code) else: return -1
os.wifexited() example 8
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED, _WTERMSIG=os.WTERMSIG, _wifexited=os.wifexited, _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED, _WSTOPSIG=os.WSTOPSIG): """All callers to this function MUST hold self._waitpid_lock.""" # This method is called (indirectly) by __del__, so it cannot # refer to anything outside of its local scope. if _WIFSIGNALED(sts): self.returncode = -_WTERMSIG(sts) elif _wifexited(sts): self.returncode = _WEXITSTATUS(sts) elif _WIFSTOPPED(sts): self.returncode = -_WSTOPSIG(sts) else: # Should never happen raise SubprocessError("Unknown child exit status!")
os.wifexited() example 9
def poll(self, flag=os.WNOHANG): if self.returncode is None: while True: try: pid, sts = os.waitpid(self.pid, flag) except OSError as e: # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None else: break if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) else: assert os.wifexited(sts) self.returncode = os.WEXITSTATUS(sts) return self.returncode
Archived version
os.wifexited()
in Python is used for validation, os.wifexited ()
Whether the process using the exit (2) system call . This method takes the process status code returned by the os.system (), os.wait (), or os.waitpid () methods as a parameter and returns True if the process exited using system call exit (2) , otherwise it returns False .
Syntax: os.wifexited (status)
Parameter:
status: This parameter takes process status code (an integer value) as returned by os.system (), os.wait () or os.waitpid () method.Return type: This method returns True if the process exited using exit (2) system call else returns False.
Code: Method usage os.wifexited ()
|
Exit:
In first child process Process ID: 11614 Hello! Geeks First child exiting .. In second child process Process ID: 11615 Hey! There Second child aborted In parent process First child exited using exit (2) system call. Second child does not exited using exit (2) system call.
Links: https://docs.python.org/3/library/os.html#os.wifexited