MCPcopy Create free account
hub / github.com/pexpect/pexpect / read_nonblocking

Method read_nonblocking

pexpect/popen_spawn.py:65–98  ·  view source on GitHub ↗
(self, size, timeout)

Source from the content-addressed store, hash-verified

63 _read_reached_eof = False
64
65 def read_nonblocking(self, size, timeout):
66 buf = self._buf
67 if self._read_reached_eof:
68 # We have already finished reading. Use up any buffered data,
69 # then raise EOF
70 if buf:
71 self._buf = buf[size:]
72 return buf[:size]
73 else:
74 self.flag_eof = True
75 raise EOF('End Of File (EOF).')
76
77 if timeout == -1:
78 timeout = self.timeout
79 elif timeout is None:
80 timeout = 1e6
81
82 t0 = time.time()
83 while (time.time() - t0) < timeout and size and len(buf) < size:
84 try:
85 incoming = self._read_queue.get_nowait()
86 except Empty:
87 break
88 else:
89 if incoming is None:
90 self._read_reached_eof = True
91 break
92
93 buf += self._decoder.decode(incoming, final=False)
94
95 r, self._buf = buf[:size], buf[size:]
96
97 self._log(r, 'read')
98 return r
99
100 def _read_incoming(self):
101 """Run in a thread to move output from a pipe to a queue."""

Callers

nothing calls this directly

Calls 3

EOFClass · 0.85
decodeMethod · 0.80
_logMethod · 0.80

Tested by

no test coverage detected