Skip to content

Run LMS stream processes in their own process group#1096

Open
stamateviorel wants to merge 1 commit into
micro-nova:mainfrom
stamateviorel:fix/lms-process-group-cleanup
Open

Run LMS stream processes in their own process group#1096
stamateviorel wants to merge 1 commit into
micro-nova:mainfrom
stamateviorel:fix/lms-process-group-cleanup

Conversation

@stamateviorel

Copy link
Copy Markdown
Contributor

What does this change intend to accomplish?

LMS.disconnect() falls back to os.killpg(self.proc.pid, SIGKILL), but the spawned squeezelite/metadata processes were never made process-group leaders, so proc.pid is not a valid pgid — the killpg either fails or signals the parent's group. This starts both children with preexec_fn=os.setpgrp so each owns its own group, kills via os.killpg(os.getpgid(pid)), and tolerates ProcessLookupError when the process already exited (previously an exception escaped during stream teardown).

Running in production on our unit; stream stop/reassign no longer leaves orphaned squeezelite processes behind.

Checklist

  • Have you tested your changes and ensured they work? (in production on a real AmpliPi)
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • If applicable, have you updated the CHANGELOG?
  • Does your submission pass linting & tests? (python -m py_compile clean; happy to fix anything CI flags)

disconnect() falls back to os.killpg(self.proc.pid, SIGKILL), but the
spawned process was never made a process-group leader, so proc.pid is
not a valid pgid: the killpg either fails or signals the parent's whole
group. Start both squeezelite and the metadata reader with
preexec_fn=os.setpgrp so each owns its group, kill via
os.killpg(os.getpgid(pid)) on the real group, and tolerate
ProcessLookupError when the process already exited.

Signed-off-by: Stamate Viorel <stamate.viorel@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@stamateviorel
stamateviorel force-pushed the fix/lms-process-group-cleanup branch from a5f1510 to c66283a Compare July 12, 2026 14:25
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.56%. Comparing base (7499989) to head (c66283a).
⚠️ Report is 103 commits behind head on main.

Files with missing lines Patch % Lines
amplipi/streams/lms.py 0.00% 10 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1096      +/-   ##
==========================================
- Coverage   50.67%   50.56%   -0.11%     
==========================================
  Files          40       41       +1     
  Lines        7154     7509     +355     
==========================================
+ Hits         3625     3797     +172     
- Misses       3529     3712     +183     
Flag Coverage Δ
unittests 50.56% <0.00%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants