File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1648,7 +1648,19 @@ def _attempt_delivery_of_any_pending_cancel(self) -> None:
16481648 if not self ._cancel_status .effectively_cancelled :
16491649 return
16501650
1651- self ._attempt_abort (RaiseCancel (self ._cancel_status ._scope ._cancel_reason ))
1651+ if (reason := self ._cancel_status ._scope ._cancel_reason ) is not None :
1652+ cancelled = Cancelled ._create (
1653+ source = reason .source ,
1654+ reason = reason .reason ,
1655+ source_task = reason .source_task ,
1656+ )
1657+ else :
1658+ cancelled = Cancelled ._create (source = "unknown" , reason = "misnesting" )
1659+
1660+ self ._attempt_abort (RaiseCancel (cancelled ))
1661+ # Clear reference to pass gc tests. `RaiseCancel` keeps the `Cancelled`
1662+ # alive until it's used.
1663+ del cancelled
16521664
16531665 def _attempt_delivery_of_pending_ki (self ) -> None :
16541666 assert self ._runner .ki_pending
@@ -1663,15 +1675,8 @@ def raise_cancel() -> NoReturn:
16631675
16641676
16651677class RaiseCancel :
1666- def __init__ (self , reason : CancelReason | None ) -> None :
1667- if reason is None :
1668- self .cancelled = Cancelled ._create (source = "unknown" , reason = "misnesting" )
1669- else :
1670- self .cancelled = Cancelled ._create (
1671- source = reason .source ,
1672- reason = reason .reason ,
1673- source_task = reason .source_task ,
1674- )
1678+ def __init__ (self , cancelled : Cancelled ) -> None :
1679+ self .cancelled = cancelled
16751680
16761681 def __call__ (self ) -> NoReturn :
16771682 try :
You can’t perform that action at this time.
0 commit comments