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

Method read_nonblocking

pexpect/socket_pexpect.py:119–145  ·  view source on GitHub ↗

Read from the file descriptor and return the result as a string. The read_nonblocking method of :class:`SpawnBase` assumes that a call to os.read will not block (timeout parameter is ignored). This is not the case for POSIX file-like objects such as sockets and seri

(self, size=1, timeout=-1)

Source from the content-addressed store, hash-verified

117 self.socket.settimeout(saved_timeout)
118
119 def read_nonblocking(self, size=1, timeout=-1):
120 """
121 Read from the file descriptor and return the result as a string.
122
123 The read_nonblocking method of :class:`SpawnBase` assumes that a call
124 to os.read will not block (timeout parameter is ignored). This is not
125 the case for POSIX file-like objects such as sockets and serial ports.
126
127 Use :func:`select.select`, timeout is implemented conditionally for
128 POSIX systems.
129
130 :param int size: Read at most *size* bytes.
131 :param int timeout: Wait timeout seconds for file descriptor to be
132 ready to read. When -1 (default), use self.timeout. When 0, poll.
133 :return: String containing the bytes read
134 """
135 if timeout == -1:
136 timeout = self.timeout
137 try:
138 with self._timeout(timeout):
139 s = self.socket.recv(size)
140 if s == b'':
141 self.flag_eof = True
142 raise EOF("Socket closed")
143 return s
144 except socket.timeout:
145 raise TIMEOUT("Timeout exceeded.")

Callers

nothing calls this directly

Calls 3

_timeoutMethod · 0.95
EOFClass · 0.85
TIMEOUTClass · 0.85

Tested by

no test coverage detected