本文整理汇总了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)
示例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