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

View file

@ -8,6 +8,9 @@
config = lib.mkIf config.frogeye.desktop.xorg { config = lib.mkIf config.frogeye.desktop.xorg {
boot.kernelModules = [ "i2c-dev" ]; # Allows using ddcutil boot.kernelModules = [ "i2c-dev" ]; # Allows using ddcutil
programs.sway.enable = true; programs.sway.enable = true;
security.pam.services.swaylock.enable = true; # Let HM handle this
# Otherwise the screen is locked twice, the second one with screen off
# TODO Can we maybe use this instead?
security.rtkit.enable = true; # Recommended for pipewire security.rtkit.enable = true; # Recommended for pipewire
services = { services = {
blueman.enable = true; blueman.enable = true;