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
736
755
the :class:`~trio.CancelScope` constructor.
737
756
"""
757
+
ifself._relative_deadline!=inf:
758
+
assertself._deadline==inf
759
+
warnings.warn(
760
+
DeprecationWarning(
761
+
"unentered relative cancel scope does not have an absolute deadline. Use `.relative_deadline`",
762
+
),
763
+
stacklevel=2,
764
+
)
765
+
returncurrent_time() +self._relative_deadline
738
766
returnself._deadline
739
767
740
768
@deadline.setter
741
769
defdeadline(self, new_deadline: float) ->None:
770
+
ifisnan(new_deadline):
771
+
raiseValueError("deadline must not be NaN")
772
+
ifself._relative_deadline!=inf:
773
+
assertself._deadline==inf
774
+
warnings.warn(
775
+
DeprecationWarning(
776
+
"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.",
777
+
),
778
+
stacklevel=2,
779
+
)
780
+
self._relative_deadline=inf
742
781
withself._might_change_registered_deadline():
743
782
self._deadline=float(new_deadline)
744
783
784
+
@property
785
+
defrelative_deadline(self) ->float:
786
+
ifself._has_been_entered:
787
+
returnself._deadline-current_time()
788
+
elifself._deadline!=inf:
789
+
assertself._relative_deadline==inf
790
+
raiseRuntimeError(
791
+
"unentered non-relative cancel scope does not have a relative deadline",
0 commit comments