def open(self):
"""Starts the subprocess, does nothing if it is already closed"""
if self.status:
return
cmd = shlex.split(self.cmd)
self._child = subprocess.Popen(
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None
)
# make stdout non-blocking
stdout_fd = self._child.stdout.fileno()
stdout_fl = fcntl.fcntl(stdout_fd, fcntl.F_GETFL) | os.O_NONBLOCK
fcntl.fcntl(stdout_fd, fcntl.F_SETFL, stdout_fl)
# prepare for timeout handing
self._poll = select.poll()
self._poll.register(self._child.stdout.fileno())
self.status = 1
评论列表
文章目录