當前位置: 首頁>>代碼示例>>Python>>正文


Python subprocess._eintr_retry_call方法代碼示例

本文整理匯總了Python中subprocess._eintr_retry_call方法的典型用法代碼示例。如果您正苦於以下問題:Python subprocess._eintr_retry_call方法的具體用法?Python subprocess._eintr_retry_call怎麽用?Python subprocess._eintr_retry_call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在subprocess的用法示例。


在下文中一共展示了subprocess._eintr_retry_call方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_eintr_retry_call

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import _eintr_retry_call [as 別名]
def test_eintr_retry_call(self):
        record_calls = []
        def fake_os_func(*args):
            record_calls.append(args)
            if len(record_calls) == 2:
                raise OSError(errno.EINTR, "fake interrupted system call")
            return tuple(reversed(args))

        self.assertEqual((999, 256),
                         subprocess._eintr_retry_call(fake_os_func, 256, 999))
        self.assertEqual([(256, 999)], record_calls)
        # This time there will be an EINTR so it will loop once.
        self.assertEqual((666,),
                         subprocess._eintr_retry_call(fake_os_func, 666))
        self.assertEqual([(256, 999), (666,), (666,)], record_calls) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:test_subprocess.py

示例2: wait

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import _eintr_retry_call [as 別名]
def wait(self, timeout=None,
           poll_initial_interval=0.001,
           poll_max_interval=0.05):  # pylint: disable=arguments-differ
    """Implements python3's timeout support.

    Raises:
    - TimeoutExpired when more than timeout seconds were spent waiting for the
      process.
    """
    assert timeout is None or isinstance(timeout, (int, float)), timeout
    if timeout is None:
      super(Popen, self).wait()
    elif self.returncode is None:
      if sys.platform == 'win32':
        WAIT_TIMEOUT = 258
        result = subprocess._subprocess.WaitForSingleObject(
            self._handle, int(timeout * 1000))
        if result == WAIT_TIMEOUT:
          raise TimeoutExpired(self.args, timeout)
        self.returncode = subprocess._subprocess.GetExitCodeProcess(
            self._handle)
      else:
        # If you think the following code is horrible, it's because it is
        # inspired by python3's stdlib.
        end = time.time() + timeout
        delay = poll_initial_interval
        while True:
          try:
            pid, sts = subprocess._eintr_retry_call(
                os.waitpid, self.pid, os.WNOHANG)
          except OSError as e:
            if e.errno != errno.ECHILD:
              raise
            pid = self.pid
            sts = 0
          if pid == self.pid:
            # This sets self.returncode.
            self._handle_exitstatus(sts)
            break
          remaining = end - time.time()
          if remaining <= 0:
            raise TimeoutExpired(self.args, timeout)
          delay = min(delay * 2, remaining, poll_max_interval)
          time.sleep(delay)

    if not self.end:
      # communicate() uses wait() internally.
      self.end = time.time()
    self._cleanup()
    return self.returncode 
開發者ID:luci,項目名稱:luci-py,代碼行數:52,代碼來源:subprocess42.py


注:本文中的subprocess._eintr_retry_call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。