| 55 | |
| 56 | |
| 57 | def drain(pipe, destination, state, stop): |
| 58 | try: |
| 59 | with destination.open("xb", buffering=0) as stream: |
| 60 | while True: |
| 61 | data = pipe.read(4096) |
| 62 | if not data: |
| 63 | break |
| 64 | state["seen"] += len(data) |
| 65 | part = memoryview(data)[:max(0, LOG_CAP - state["saved"])] |
| 66 | while part: |
| 67 | size = stream.write(part) |
| 68 | if not size: |
| 69 | raise OSError("short evidence write") |
| 70 | state["saved"] += size |
| 71 | part = part[size:] |
| 72 | if state["seen"] > LOG_CAP: |
| 73 | state["overflow"] = True |
| 74 | stop.set() |
| 75 | except (OSError, ValueError) as exc: |
| 76 | state["error"] = str(exc) |
| 77 | stop.set() |
| 78 | finally: |
| 79 | pipe.close() |
| 80 | |
| 81 | |
| 82 | def group_exists(pid): |