You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:func:`trio.move_on_after` and :func:`trio.fail_after` previously set the deadline relative to initialization time, instead of more intuitively upon entering the context manager. This might change timeouts if a program relied on this behavior. If you want to restore previous behavior you should instead use ``trio.move_on_at(trio.current_time() + ...)``.
2
+
flake8-async has a new rule to catch this, in case you're supporting older trio versions. See :ref:`ASYNC122`.
:meth:`CancelScope.relative_deadline` and :meth:`CancelScope.is_relative` added, as well as a ``relative_deadline`` parameter to ``__init__``. This allows initializing scopes ahead of time, but where the specified relative deadline doesn't count down until the scope is entered.
this can be overridden by the ``deadline=`` argument to
735
754
the :class:`~trio.CancelScope` constructor.
736
755
"""
756
+
ifself._relative_deadline!=inf:
757
+
assertself._deadline==inf
758
+
warnings.warn(
759
+
DeprecationWarning(
760
+
"unentered relative cancel scope does not have an absolute deadline. Use `.relative_deadline`",
761
+
),
762
+
stacklevel=2,
763
+
)
764
+
returncurrent_time() +self._relative_deadline
737
765
returnself._deadline
738
766
739
767
@deadline.setter
740
768
defdeadline(self, new_deadline: float) ->None:
769
+
ifisnan(new_deadline):
770
+
raiseValueError("deadline must not be NaN")
771
+
ifself._relative_deadline!=inf:
772
+
assertself._deadline==inf
773
+
warnings.warn(
774
+
DeprecationWarning(
775
+
"unentered relative cancel scope does not have an absolute deadline. Transforming into an absolute cancel scope. First set `.relative_deadline = math.inf` if you do want an absolute cancel scope.",
776
+
),
777
+
stacklevel=2,
778
+
)
779
+
self._relative_deadline=inf
741
780
withself._might_change_registered_deadline():
742
781
self._deadline=float(new_deadline)
743
782
783
+
@property
784
+
defrelative_deadline(self) ->float:
785
+
ifself._has_been_entered:
786
+
returnself._deadline-current_time()
787
+
elifself._deadline!=inf:
788
+
assertself._relative_deadline==inf
789
+
raiseRuntimeError(
790
+
"unentered non-relative cancel scope does not have a relative deadline",
0 commit comments