frobar: Proper handling of EOF
I now get why the Python documentation really insists you use .communicate().
This commit is contained in:
parent
465c2347cb
commit
0ac0ad1267
2 changed files with 12 additions and 1 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue