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)
| 120 | self.write(s) |
| 121 | |
| 122 | def read_nonblocking(self, size=1, timeout=-1): |
| 123 | """ |
| 124 | Read from the file descriptor and return the result as a string. |
| 125 | |
| 126 | The read_nonblocking method of :class:`SpawnBase` assumes that a call |
| 127 | to os.read will not block (timeout parameter is ignored). This is not |
| 128 | the case for POSIX file-like objects such as sockets and serial ports. |
| 129 | |
| 130 | Use :func:`select.select`, timeout is implemented conditionally for |
| 131 | POSIX systems. |
| 132 | |
| 133 | :param int size: Read at most *size* bytes. |
| 134 | :param int timeout: Wait timeout seconds for file descriptor to be |
| 135 | ready to read. When -1 (default), use self.timeout. When 0, poll. |
| 136 | :return: String containing the bytes read |
| 137 | """ |
| 138 | if os.name == 'posix': |
| 139 | if timeout == -1: |
| 140 | timeout = self.timeout |
| 141 | rlist = [self.child_fd] |
| 142 | wlist = [] |
| 143 | xlist = [] |
| 144 | if self.use_poll: |
| 145 | rlist = poll_ignore_interrupts(rlist, timeout) |
| 146 | else: |
| 147 | rlist, wlist, xlist = select_ignore_interrupts( |
| 148 | rlist, wlist, xlist, timeout |
| 149 | ) |
| 150 | if self.child_fd not in rlist: |
| 151 | raise TIMEOUT('Timeout exceeded.') |
| 152 | return super(fdspawn, self).read_nonblocking(size) |
nothing calls this directly
no test coverage detected