| 831 | ] |
| 832 | |
| 833 | class MyProtocol(asyncio.SubprocessProtocol): |
| 834 | def __init__(self, exit_future: asyncio.Future) -> None: |
| 835 | self.exit_future = exit_future |
| 836 | |
| 837 | def pipe_data_received(self, fd, data) -> None: |
| 838 | events.append(('pipe_data_received', fd, data)) |
| 839 | self.exit_maybe() |
| 840 | |
| 841 | def pipe_connection_lost(self, fd, exc) -> None: |
| 842 | events.append(('pipe_connection_lost', fd)) |
| 843 | self.exit_maybe() |
| 844 | |
| 845 | def process_exited(self) -> None: |
| 846 | events.append('process_exited') |
| 847 | self.exit_maybe() |
| 848 | |
| 849 | def exit_maybe(self): |
| 850 | # Only exit when we got all expected events |
| 851 | if len(events) >= len(expected): |
| 852 | self.exit_future.set_result(True) |
| 853 | |
| 854 | async def main() -> None: |
| 855 | loop = asyncio.get_running_loop() |