pytest-dev / pytest-dev/pytest-timeout
signals should be blocked in thread when using thread timeout method
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 258
- Forks
- 69
- PR merge metrics
- No merged PRs in 30d
Description
Original report by Christopher Hunt (Bitbucket: chrahunt, GitHub: chrahunt).
Currently in Python it's only possible to change your signal disposition on a thread-specific basis using signal.pthread_sigmask. When a test depends on certain signals being blocked but we use the thread method for pytest-timeout, the signal is still received by the process via the internal thread maintained by pytest-timeout and it is then propagated to the main thread by the Python runtime.
The fix is to surround the thread start with something like
old_mask = signal.pthread_sigmask(signal.SIG_SETMASK, range(1, signal.NSIG))
t.start()
signal.pthread_sigmask(signal.SIG_SETMASK, old_mask)
This works because the signal mask is inherited by spawned threads, and also avoids a potential race condition if we were to set the signal mask inside the thread target function itself.
Currently I work around this issue by patching threading.Thread.start to do the same as above.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the thread-based timeout implementation in pytest-timeout and read how its internal thread is started. Check the signal.pthread_sigmask behavior described in the issue, then verify that signals remain blocked for the timeout thread without changing the existing timeout behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100