frobar: Proper handling of EOF

I now get why the Python documentation really insists you use
.communicate().
This commit is contained in:
Geoffrey Frogeye 2025-12-21 12:02:17 +01:00
parent 465c2347cb
commit 0ac0ad1267
2 changed files with 12 additions and 1 deletions

View file

@ -375,12 +375,18 @@ class Screen(ComposableText):
markup = self.get_markup()
# sys.stdout.write(markup) # DEBUG
proc.stdin.write(markup.encode())
try:
await proc.stdin.drain()
except BrokenPipeError:
log.error("zelbar: broken pipe, killing")
proc.kill()
return
await self.refresh.wait()
self.refresh.clear()
async def action_handler(proc: asyncio.subprocess.Process) -> None:
assert proc.stdout
while proc.returncode is None:
while not proc.stdout.at_eof():
line = await proc.stdout.readline()
try:
command = line.decode().strip()
@ -393,6 +399,8 @@ class Screen(ComposableText):
log.error("Unknown command: %s", command)
continue
callback()
log.error("zelbar: EOF reached, killing")
proc.kill()
refresher_task = self.bar.add_long_running_task(refresher(proc))
action_handler_task = self.bar.add_long_running_task(action_handler(proc))