-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
move_on_ and fail_ functions accepts shield kwarg #3051
move_on_ and fail_ functions accepts shield kwarg #3051
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3051 +/- ##
==========================================
- Coverage 99.63% 99.62% -0.02%
==========================================
Files 120 120
Lines 17832 17857 +25
Branches 3204 3210 +6
==========================================
+ Hits 17767 17790 +23
- Misses 46 48 +2
Partials 19 19
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment about the tests, I don't have much of an opinion on the feature itself.
src/trio/_tests/test_timeouts.py
Outdated
@@ -75,6 +75,66 @@ async def sleep_3() -> None: | |||
await check_takes_about(sleep_3, TARGET) | |||
|
|||
|
|||
@slow | |||
async def test_move_on_after_shields_from_outer() -> None: | |||
duration = 0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is using sleep a checkpoint, can you use a checkpoint (or trio.sleep(0)) instead of a hardcoded small value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i use 0, i don't think i can make use of check_takes_about
because it checks dur / expected_dur < 1.5
, and expected_dur = 0
in this case. The docstring also says that they observe overruns when they sleep for 0.05s, so I picked 0.1s here.
Alternatively, I can use a different way to test whether we actually sleep (instead of using check_takes_about
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So don't use check_takes_about
(and don't mark this test as slow). Instead do something like:
try:
await trio.lowlevel.checkpoint()
except trio.Cancelled:
pytest.fail("shield didn't work")
inner.shield = False
with pytest.raises(trio.Cancelled):
await trio.lowlevel.checkpoint()
src/trio/_tests/test_timeouts.py
Outdated
@@ -75,6 +75,66 @@ async def sleep_3() -> None: | |||
await check_takes_about(sleep_3, TARGET) | |||
|
|||
|
|||
@slow | |||
async def test_move_on_after_shields_from_outer() -> None: | |||
duration = 0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So don't use check_takes_about
(and don't mark this test as slow). Instead do something like:
try:
await trio.lowlevel.checkpoint()
except trio.Cancelled:
pytest.fail("shield didn't work")
inner.shield = False
with pytest.raises(trio.Cancelled):
await trio.lowlevel.checkpoint()
I think these changes are good, but I am curious about the root issue behind this. Are there use cases where it's not sufficient to set the shield to True slightly after it's initialized? And even in that case, couldn't you just create the cancel scope, set the |
This is sufficient, and this change is just to have a one-liner syntax for this behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I was looking at whether this has been discussed before and found #147 where @njsmith thinks that making On the other other hand, the "library" I'm looking at (hypercorn's TCP send implementation) manually sets (really this comment belongs in the related issue but... already written, what can you do.) |
Sorry for the delay, have been ill this week. @A5rocks I would say that if we're trying to encourage use of shield+timeout over just shield-without-timeout -- which I think we are -- then we shouldn't make shield+timeout be cumbersome to write. Currently one must do either
or
or
none of which exactly roll off the fingers. I think we should allow
so people aren't pushed toward the more uncancellable-hang-prone
If we don't want to make shielding visible in Overall I think shielding is more important in moderately-complex-and-up programs than Trio's initial design gave it credit for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good then!
Hey @agnesnatasya, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂 If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:
If you want to read more, here's the relevant section in our contributing guide. Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you. If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out! |
make
move_on_at
,move_on_after
,fail_at
andfail_after
accepts shield as a kwarg.Closes #3052