当前位置: 首页>>代码示例>>Python>>正文


Python os.WNOHANG属性代码示例

本文整理汇总了Python中os.WNOHANG属性的典型用法代码示例。如果您正苦于以下问题:Python os.WNOHANG属性的具体用法?Python os.WNOHANG怎么用?Python os.WNOHANG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在os的用法示例。


在下文中一共展示了os.WNOHANG属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _internal_poll

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
                _WNOHANG=os.WNOHANG, _os_error=os.error, _ECHILD=errno.ECHILD):
            """Check if child process has terminated.  Returns returncode
            attribute.

            This method is called by __del__, so it cannot reference anything
            outside of the local scope (nor can any methods it calls).

            """
            if self.returncode is None:
                try:
                    pid, sts = _waitpid(self.pid, _WNOHANG)
                    if pid == self.pid:
                        self._handle_exitstatus(sts)
                except _os_error as e:
                    if _deadstate is not None:
                        self.returncode = _deadstate
                    elif e.errno == _ECHILD:
                        # This happens if SIGCLD is set to be ignored or
                        # waiting for child processes has otherwise been
                        # disabled for our process.  This child is dead, we
                        # can't get the status.
                        # http://bugs.python.org/issue15756
                        self.returncode = 0
            return self.returncode 
开发者ID:war-and-code,项目名称:jawfish,代码行数:27,代码来源:subprocess.py

示例2: reap_children

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def reap_children():
    """Use this function at the end of test_main() whenever sub-processes
    are started.  This will help ensure that no extra children (zombies)
    stick around to hog resources and create problems when looking
    for refleaks.
    """

    # Reap all our dead child processes so we don't leave zombies around.
    # These hog resources and might be causing some of the buildbots to die.
    if hasattr(os, 'waitpid'):
        any_process = -1
        while True:
            try:
                # This will raise an exception on Windows.  That's ok.
                pid, status = os.waitpid(any_process, os.WNOHANG)
                if pid == 0:
                    break
            except:
                break 
开发者ID:war-and-code,项目名称:jawfish,代码行数:21,代码来源:support.py

示例3: _zombie_reaper

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def _zombie_reaper(self):
        while True:
            try:
                res = os.waitpid(-1, os.WNOHANG)
                # don't sleep or stop if a zombie process was found
                # as there could be more
                if res != (0, 0):
                    continue
            except ChildProcessError:
                # There are no child processes yet (or they have been killed)
                pass
            except os.error:
                LOG.exception("Got OS error while reaping zombie processes")
            if self._terminate_called.isSet():
                break
            time.sleep(1) 
开发者ID:openstack,项目名称:zun,代码行数:18,代码来源:service.py

示例4: wait_for_child_and_forward_signals

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def wait_for_child_and_forward_signals(child_pid, process_name):
    """Wait for a child to terminate and in the meantime forward all signals
    that the current process receives to this child.
    @return a tuple of exit code and resource usage of the child as given by os.waitpid
    """
    block_all_signals()

    while True:
        logging.debug("Waiting for signals")
        signum = signal.sigwait(_ALL_SIGNALS)
        if signum == signal.SIGCHLD:
            pid, exitcode, ru_child = os.wait4(-1, os.WNOHANG)
            while pid != 0:
                if pid == child_pid:
                    return exitcode, ru_child
                else:
                    logging.debug("Received unexpected SIGCHLD for PID %s", pid)
                pid, exitcode, ru_child = os.wait4(-1, os.WNOHANG)

        else:
            _forward_signal(signum, child_pid, process_name) 
开发者ID:sosy-lab,项目名称:benchexec,代码行数:23,代码来源:container.py

示例5: _internal_poll

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
                _WNOHANG=os.WNOHANG, _os_error=os.error):
            """Check if child process has terminated.  Returns returncode
            attribute.

            This method is called by __del__, so it cannot reference anything
            outside of the local scope (nor can any methods it calls).

            """
            if self.returncode is None:
                try:
                    pid, sts = _waitpid(self.pid, _WNOHANG)
                    if pid == self.pid:
                        self._handle_exitstatus(sts)
                except _os_error:
                    if _deadstate is not None:
                        self.returncode = _deadstate
            return self.returncode 
开发者ID:glmcdona,项目名称:meddle,代码行数:20,代码来源:subprocess.py

示例6: _internal_poll

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
                _WNOHANG=os.WNOHANG, _os_error=os.error, _ECHILD=errno.ECHILD):
            """Check if child process has terminated.  Returns returncode
            attribute.

            This method is called by __del__, so it cannot reference anything
            outside of the local scope (nor can any methods it calls).

            """
            if self.returncode is None:
                try:
                    pid, sts = _waitpid(self.pid, _WNOHANG)
                    if pid == self.pid:
                        self._handle_exitstatus(sts)
                except _os_error as e:
                    if _deadstate is not None:
                        self.returncode = _deadstate
                    if e.errno == _ECHILD:
                        # This happens if SIGCLD is set to be ignored or
                        # waiting for child processes has otherwise been
                        # disabled for our process.  This child is dead, we
                        # can't get the status.
                        # http://bugs.python.org/issue15756
                        self.returncode = 0
            return self.returncode 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:subprocess.py

示例7: wait

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def wait(self):
            """Wait for child process to terminate.  Returns returncode
            attribute."""
            while self.returncode is None:
                try:
                    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
                except OSError as e:
                    if e.errno != errno.ECHILD:
                        raise
                    # This happens if SIGCLD is set to be ignored or waiting
                    # for child processes has otherwise been disabled for our
                    # process.  This child is dead, we can't get the status.
                    pid = self.pid
                    sts = 0
                # Check the pid and loop as waitpid has been known to return
                # 0 even without WNOHANG in odd situations.  issue14396.
                if pid == self.pid:
                    self._handle_exitstatus(sts)
            return self.returncode 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:subprocess.py

示例8: wait_impl

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def wait_impl(self, cpid):
        option = os.WNOHANG
        if sys.platform.startswith('aix'):
            # Issue #11185: wait4 is broken on AIX and will always return 0
            # with WNOHANG.
            option = 0
        for i in range(10):
            # wait4() shouldn't hang, but some of the buildbots seem to hang
            # in the forking tests.  This is an attempt to fix the problem.
            spid, status, rusage = os.wait4(cpid, option)
            if spid == cpid:
                break
            time.sleep(1.0)
        self.assertEqual(spid, cpid)
        self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
        self.assertTrue(rusage) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_wait4.py

示例9: poll

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:forking.py

示例10: cleanup_defunct_processes

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def cleanup_defunct_processes():
  """Cleans up defunct processes."""
  # Defunct processes happen only on unix platforms.
  if environment.platform() != 'WINDOWS':
    while True:
      try:
        # Matches any defunct child process.
        p, _ = os.waitpid(-1, os.WNOHANG)
        if not p:
          break

        logs.log('Clearing defunct process %s.' % str(p))
      except:
        break


# Note: changes to this function may require changes to untrusted_runner.proto.
# This should only be used for running target black box applications which
# return text output. 
开发者ID:google,项目名称:clusterfuzz,代码行数:21,代码来源:process_handler.py

示例11: platformWait

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def platformWait(self):
        # Wait for a mach message on the exception port
        exc = None
        while exc == None:
            exc = self._getNextExc()
        #e2 = self._getNextExc(timeout=0)
        #if e2 != None:
        #print "ALSO GOT",e2

        # Suspend the task so reading etc is safe...
        self.libc.task_suspend(self.task)

        # Sometimes there are still posix signals anyway...
        while os.waitpid(-1, os.WNOHANG) != (0,0):
            pass

        res = self.buildExcResp(exc)

        x = self.libc.mach_msg(addrof(res), MACH_SEND_MSG, ctypes.sizeof(res),0,MACH_MSG_TIMEOUT_NONE,MACH_PORT_NULL)
        if x != 0:
            raise Exception('mach_msg MACH_SEND_MSG failed: 0x%.8x' % (x,))

        return exc 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:25,代码来源:darwin.py

示例12: registerReapProcessHandler

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def registerReapProcessHandler(pid, process):
    """
    Register a process handler for the given pid, in case L{reapAllProcesses}
    is called.

    @param pid: the pid of the process.
    @param process: a process handler.
    """
    if pid in reapProcessHandlers:
        raise RuntimeError("Try to register an already registered process.")
    try:
        auxPID, status = os.waitpid(pid, os.WNOHANG)
    except:
        log.msg('Failed to reap %d:' % pid)
        log.err()
        auxPID = None
    if auxPID:
        process.processEnded(status)
    else:
        # if auxPID is 0, there are children but none have exited
        reapProcessHandlers[pid] = process 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:process.py

示例13: wait

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def wait(self, timeout=None, endtime=None):
            """Wait for child process to terminate.  Returns returncode
            attribute."""
            if self.returncode is not None:
                return self.returncode

            # endtime is preferred to timeout.  timeout is only used for
            # printing.
            if endtime is not None or timeout is not None:
                if endtime is None:
                    endtime = _time() + timeout
                elif timeout is None:
                    timeout = self._remaining_time(endtime)

            if endtime is not None:
                # Enter a busy loop if we have a timeout.  This busy loop was
                # cribbed from Lib/threading.py in Thread.wait() at r71065.
                delay = 0.0005 # 500 us -> initial delay of 1 ms
                while True:
                    (pid, sts) = self._try_wait(os.WNOHANG)
                    assert pid == self.pid or pid == 0
                    if pid == self.pid:
                        self._handle_exitstatus(sts)
                        break
                    remaining = self._remaining_time(endtime)
                    if remaining <= 0:
                        raise TimeoutExpired(self.args, timeout)
                    delay = min(delay * 2, remaining, .05)
                    time.sleep(delay)
            else:
                while self.returncode is None:
                    (pid, sts) = self._try_wait(0)
                    # Check the pid and loop as waitpid has been known to return
                    # 0 even without WNOHANG in odd situations.  issue14396.
                    if pid == self.pid:
                        self._handle_exitstatus(sts)
            return self.returncode 
开发者ID:war-and-code,项目名称:jawfish,代码行数:39,代码来源:subprocess.py

示例14: collect_children

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def collect_children(self):
        """Internal routine to wait for children that have exited."""
        if self.active_children is None: return
        while len(self.active_children) >= self.max_children:
            # XXX: This will wait for any child process, not just ones
            # spawned by this library. This could confuse other
            # libraries that expect to be able to wait for their own
            # children.
            try:
                pid, status = os.waitpid(0, 0)
            except os.error:
                pid = None
            if pid not in self.active_children: continue
            self.active_children.remove(pid)

        # XXX: This loop runs more system calls than it ought
        # to. There should be a way to put the active_children into a
        # process group and then use os.waitpid(-pgid) to wait for any
        # of that set, but I couldn't find a way to allocate pgids
        # that couldn't collide.
        for child in self.active_children:
            try:
                pid, status = os.waitpid(child, os.WNOHANG)
            except os.error:
                pid = None
            if not pid: continue
            try:
                self.active_children.remove(pid)
            except ValueError as e:
                raise ValueError('%s. x=%d and list=%r' % (e.message, pid,
                                                           self.active_children)) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:33,代码来源:socketserver.py

示例15: _wait_pid

# 需要导入模块: import os [as 别名]
# 或者: from os import WNOHANG [as 别名]
def _wait_pid(self, process, wait):
        timeout = time.time() + wait
        while time.time() < timeout:
            pid, _ = os.waitpid(process.pid, os.WNOHANG)
            if pid == process.pid:
                return True
            time.sleep(0.1)
        return False 
开发者ID:latchset,项目名称:custodia,代码行数:10,代码来源:base.py


注:本文中的os.WNOHANG属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。