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

New signal API: trio.open_signal_receiver #619

Merged
merged 4 commits into from
Aug 23, 2018

Conversation

njsmith
Copy link
Member

@njsmith njsmith commented Aug 22, 2018

Fixes gh-354

Other changes:

  • deprecate trio.catch_signal
  • fix a few small edge-cases I noticed along the way

Fixes python-triogh-354

Other changes:

- deprecate trio.catch_signal
- fix a few small edge-cases I noticed along the way
@codecov
Copy link

codecov bot commented Aug 22, 2018

Codecov Report

Merging #619 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #619      +/-   ##
==========================================
+ Coverage   99.31%   99.32%   +<.01%     
==========================================
  Files          91       91              
  Lines       10873    10933      +60     
  Branches      758      763       +5     
==========================================
+ Hits        10799    10859      +60     
  Misses         56       56              
  Partials       18       18
Impacted Files Coverage Δ
trio/_core/_entry_queue.py 100% <ø> (ø) ⬆️
trio/_core/_run.py 100% <ø> (ø) ⬆️
trio/tests/test_signals.py 100% <100%> (ø) ⬆️
trio/_signals.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f0dd7d...fac80e1. Read the comment docs.

Copy link
Member

@goodboy goodboy left a comment

Choose a reason for hiding this comment

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

Took a little while to get through but I think this looks darn good!

I a have couple small comments that definitely aren't blocking.

@@ -1,11 +1,15 @@
import signal
from contextlib import contextmanager
from collections import OrderedDict
Copy link
Member

Choose a reason for hiding this comment

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

I guess whenever 3.5 support is dropped (as soon as pypy supports 3.6?) you can just use a plain ol' dict since 3.7 ruled it stays.

Copy link
Member Author

Choose a reason for hiding this comment

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

PyPy has actually had ordered dicts by default for a while (CPython copied their implementation). But annoyingly, we also need popitem(last=False), which even in 3.7 is still an OrderedDict-only method.

Copy link
Member

Choose a reason for hiding this comment

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

which even in 3.7 is still an OrderedDict-only method.

Ahh what!?



async def test_catch_signals():
# Delete when catch_signals is removed
Copy link
Member

Choose a reason for hiding this comment

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

TODO might be handy for grep-ing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, when we remove catch_signals the test will start failing, so we won't miss it :-)

await _core.wait_all_tasks_blocked()
signal_raise(signal.SIGILL)
await _core.wait_all_tasks_blocked()
async for signum in receiver: # pragma: no branch
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth ensuring that receiver only once delivers a signal raised multiple times prior to iteration?
I guess I'm just thinking down the road if the implementation is changed (internal set-like data structure or whatever) and this behaviour should remain.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are implicitly checking that signals are coalesced, because if they weren't then when we exited the with block they'd be redelivered and cause the test process to dump core :-).

It would make sense to test this a little more explicitly... I'm going to add a little private helper to do that.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh right of course. Cool, I like explicit 👍

token = _core.current_trio_token()
token.run_sync_soon(ev.set, idempotent=True)
await ev.wait()

print(1)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe print something more descriptive?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, actually, have you considered just adding some branch logic for each
await wait_run_sync_soon_idempotent_queue_barrier() location and then just use pytest.mark.parametrize() over signals and that?

Might reduce some code unless the duplication is intentional.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a pretty complicated test that I didn't really touch here, so honestly I'm not sure what it does right now :-). I doubt it's worth messing with – if it breaks we can easily add better print statements or whatever then.

- Add a private test helper to check how many signals are pending
- Use this to explicitly test that coalescing has worked
- Use this instead of poking at the object's guts directly in existing
  tests
@njsmith
Copy link
Member Author

njsmith commented Aug 23, 2018

Added a more explicit test of signal coalescing. All comments addressed.

@@ -0,0 +1,8 @@
``trio.signal_catcher`` has been deprecated in favor of
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the rest of this PR, it looks like the function was called trio.catch_signals?

Copy link
Member Author

Choose a reason for hiding this comment

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

😧

@pquentin
Copy link
Member

Merging since @tgoodlet approved this

@pquentin pquentin merged commit 2c0cac1 into python-trio:master Aug 23, 2018
This was referenced Aug 23, 2018
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.

Remove batching from catch_signals?
3 participants