(fd)
| 28 | import fcntl |
| 29 | |
| 30 | def blockingReadFromFD(fd): |
| 31 | # Quick twist around original Twisted function |
| 32 | # Blocking read from a non-blocking file descriptor |
| 33 | output = b"" |
| 34 | |
| 35 | while True: |
| 36 | try: |
| 37 | output += os.read(fd, 8192) |
| 38 | except (OSError, IOError) as ioe: |
| 39 | if ioe.args[0] in (errno.EAGAIN, errno.EINTR): |
| 40 | # Uncomment the following line if the process seems to |
| 41 | # take a huge amount of cpu time |
| 42 | # time.sleep(0.01) |
| 43 | continue |
| 44 | else: |
| 45 | raise |
| 46 | break |
| 47 | |
| 48 | if not output: |
| 49 | raise EOFError("fd %s has been closed." % fd) |
| 50 | |
| 51 | return output |
| 52 | |
| 53 | def blockingWriteToFD(fd, data): |
| 54 | # Another quick twist |
no test coverage detected
searching dependent graphs…