Skip to content

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

Open
@pytest-timeout-bot

Description

@pytest-timeout-bot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingminor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions