tests/conftest: fix concurrent access to pexpect.spawn#1937
Merged
Bastian-Krause merged 1 commit intoJul 16, 2026
Merged
Conversation
pexpect/ptyprocess are not thread-safe. But we need a thread to keep reading the Exporter/Coordinator outputs during the tests for debugging purposes. The reader thread (calling `pexpect.spawn.read_nonblocking()`) and the main thread (calling `pexpect.spawn`'s `kill()`/`wait()`/`isalive()`) can access it concurrently. Internally, pexpect calls waitpid(2) in these methods. This behavior leads to errors such as: ptyprocess.util.PtyProcessError: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? Or: pexpect.exceptions.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? Fix this by serializing access to pexpect.spawn through a lock. Signed-off-by: Bastian Krause <bst@pengutronix.de>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1937 +/- ##
========================================
- Coverage 61.0% 61.0% -0.1%
========================================
Files 182 182
Lines 14881 14881
========================================
- Hits 9083 9081 -2
- Misses 5798 5800 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Emantor
approved these changes
Jul 15, 2026
Bastian-Krause
merged commit Jul 16, 2026
4084c8e
into
labgrid-project:master
10 of 11 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Another deep dive into our flaky CI tests:
pexpect/ptyprocess are not thread-safe. But we need a thread to keep reading the Exporter/Coordinator outputs during the tests for debugging purposes.
The reader thread (calling
pexpect.spawn.read_nonblocking()) and the main thread (callingpexpect.spawn'skill()/wait()/isalive()) can access it concurrently. Internally, pexpect calls waitpid(2) in these methods.This behavior leads to errors such as:
Or:
These errors pop up in CI from time to time: https://github.com/labgrid-project/labgrid/actions/runs/29324126371/job/87056209839
Fix this by serializing access to
pexpect.spawnthrough a lock.Checklist
Fixes #547