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

Add method = both: 1. signal + 2. thread #89

Closed
wants to merge 1 commit into from

Conversation

ep12
Copy link

@ep12 ep12 commented May 5, 2021

STATUS: rather drafty, feedback welcome. Will be modified soon.

The new method aims at combining the advantages of method = thread (reliability) and method = signal (gracefulness, ability to continue).
A new option kill_delay is added to configure how much time the test is granted to handle the timeout thrown by the signalling method. After that time has expired, the thread method is used.
Two new tests ensure that the new method works as expected, existing tests have been parameterized to include the new method.
The README now contains a small section documenting the method and its kill_delay configuration option.

Partially related (motivated by): #87.
Also related (it seems??): #88.

The new method aims at combining the advantages of `method = thread`
(reliability) and `method = signal` (gracefulness, ability to continue).
A new option `kill_delay` is added to configure how much time the test
is granted to handle the timeout thrown by the signalling method. After
that time has expired, the `thread` method is used.
Two new tests ensure that the new method works as expected, existing
tests have been parametrised to include the new method.
The README now contains a small section documenting the method and its
`kill_delay` configuration option.
Copy link
Member

@flub flub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment on lines +35 to +36
'both' tries to gracefully time out a test, after kill_delay seconds
a harsh kill is used to reliably stop the test.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to describe this in terms of the signal and thread terminology used in this help message already rather than use "gracefully" and "harsh". Maybe something more like

Suggested change
'both' tries to gracefully time out a test, after kill_delay seconds
a harsh kill is used to reliably stop the test.
'both' uses 'signal' by default, but if this fails to time out the test falls back to 'thread' after kill_delay seconds.

(but at least properly formatted 😄

the soft *signal* attempt, so you might want to switch to *thread*.
Similar to ``PYTEST_TIMEOUT``, you can specify the kill delay with the
``PYTEST_KILL_DELAY`` environment variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to also describe the tradeoffs a little: you carry the overheads of spawning a thread for each test but have the chance of not killing the entire process on each timeout while still having the reliability of ensuring you always get a working timeout.
(maybe there's better ways to phrase that)

Comment on lines +99 to +103
time.sleep(2)

# so that the signal method does not succeed
signal.signal(signal.SIGALRM, handler)
time.sleep(2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, i had to double-take to be sure this wasn't a little racy. I think it would be clearer if the new handler just does a pass and the sleep of the test clearly covers > 2s right away, say 3s.

You can even turn the new handler in a lambda if you like lambda signum, frame: pass is probably fine.

@xoviat
Copy link
Contributor

xoviat commented May 10, 2021

Make sure that this doesn't re-introduce #8.

@ep12
Copy link
Author

ep12 commented May 11, 2021

@flub: I get all the points you mentioned and will fix them, just didn't want to respond with the same text three times...
@xoviat: I don't know much about #8. At a first glance I saw that the solution was/is to just switch to thread if signal wouldn't work. Is that right?
Also, is there a test that makes sure that #8 doesn't come back? (If not, that would probably be a good thing to have, right?)
EDIT: I'll wait for #88 to be merged before rebasing and updating this pr.

@chaporgin
Copy link

I see it did not get to main branch. I still get signal only works in the main thread of the main interpreter from time to time. Cannot reliably reproduce though.

@flub
Copy link
Member

flub commented Oct 8, 2023

closing as this seems stalled

@flub flub closed this Oct 8, 2023
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.

4 participants