Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signals should be blocked in thread when using thread timeout method #33

Open
pytest-timeout-bot opened this issue Jan 20, 2019 · 1 comment
Labels
bug Something isn't working minor

Comments

@pytest-timeout-bot
Copy link

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.

@pytest-timeout-bot
Copy link
Author

Original comment by Floris Bruynooghe (Bitbucket: flub, GitHub: flub).


Great catch! Could you do a PR?

@pytest-timeout-bot pytest-timeout-bot added minor bug Something isn't working labels Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working minor
Projects
None yet
Development

No branches or pull requests

1 participant