In to_thread_run_sync(), add abandon_on_cancel= as an alias for the cancellable= flag#2841
Conversation
… flag Replaced in code and docs
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2841 +/- ##
=======================================
Coverage 99.18% 99.18%
=======================================
Files 115 115
Lines 17596 17612 +16
Branches 3143 3149 +6
=======================================
+ Hits 17453 17469 +16
Misses 99 99
Partials 44 44
|
75ed7ec to
c119c2a
Compare
There was a problem hiding this comment.
That's a much more understandable name. It's not necessary, but we could use @overload to have type checkers prevent you from passing both parameters:
@overload
async def to_thread_run_sync(
sync_fn: Callable[..., RetT],
*args: object,
thread_name: str | None = None,
abandon_on_cancel: bool,
limiter: CapacityLimiter | None = None,
) -> RetT: ...
@overload
async def to_thread_run_sync(
sync_fn: Callable[..., RetT],
*args: object,
thread_name: str | None = None,
cancellable: bool = False,
limiter: CapacityLimiter | None = None,
) -> RetT: ...236cb0f to
c119c2a
Compare
jakkdl
left a comment
There was a problem hiding this comment.
If cancellable is actually deprecated, as it's phrased in the newsfragment, then it should raise a DeprecationWarning if cancellable is specified.
Alternatives would be to forever support both arguments (yuck), or to make it deprecated later for some reason.
|
I'd sooner abandon this pull request than start raising warnings everywhere. The extra maintenance burden is 3 easy lines of code on our end, but a warning will send our users scrambling to perform busywork. Someone else should add a warning in a future PR for a real reason, like |
newsfragments/2841.feature.rst
Outdated
| @@ -0,0 +1,3 @@ | |||
| To better reflect the underlying thread handling semantics, | |||
| `trio.to_thread.run_sync` gained a new keyword argument ``abandon_on_cancel`` | |||
There was a problem hiding this comment.
This newsfragment should get a .removal. name (not .feature.) so it shows up in the "Deprecations and removals" section of the release notes.
I would write this as
To better reflect the underlying thread handling semantics,
the keyword argument for `trio.to_thread.run_sync` that was
previously called ``cancellable`` is now named ``abandon_on_cancel``.
It still does the same thing -- allow the thread to be abandoned
if the call to `trio.to_thread.run_sync` is cancelled -- but since we now
have other ways to propagate a cancellation without abandoning
the thread, "cancellable" has become somewhat of a misnomer.
The old ``cancellable`` name is now deprecated.
# Conflicts: # trio/_tests/test_threads.py
|
Guess I'm outvoted here. Hope everything goes ok downstream! |
applied suggestions from code review
I guess I don't know at what level of the stack to warn? And the mypy errors are utterly beyond me |
Sorry, I reviewed without having seen this comment or I would've responded to it initially. I have empathy for this view, but it doesn't match how we've handled all other deprecations in the past, and I think the old name is actively harmful/confusing under the new semantics. ( |
to_thread_run_sync(), add abandon_on_cancel= as an alias for the cancellable= flag
Co-authored-by: Joshua Oreman <oremanj@gmail.com>
|
I'll merge this in soon-ish unless someone has other thoughts! |
jakkdl
left a comment
There was a problem hiding this comment.
Sorry for being a pain in the butt, looks great!
|
sorry thought the merge was a merge to master not from master! |
No worries! With the ongoing updates to linters etc I wanted to double check that this passes before merging even if GitHub deemed it a safe merge :) |
As suggested in #2392 (comment)