@@ -113,9 +113,13 @@ def __init__( # pragma: no cover
113113 # This flag prevents concurrent calls to get() by user code.
114114 self .get_in_progress = False
115115
116+ # This flag marks a soon cancellation
117+ self .cancelling = False
118+
116119 # This flag marks the end of the connection.
117120 self .closed = False
118121
122+
119123 async def get (self , decode : bool | None = None ) -> Data :
120124 """
121125 Read the next message.
@@ -138,6 +142,8 @@ async def get(self, decode: bool | None = None) -> Data:
138142 :meth:`get_iter` concurrently.
139143
140144 """
145+ if self .cancelling :
146+ return
141147 if self .get_in_progress :
142148 raise ConcurrencyError ("get() or get_iter() is already running" )
143149 self .get_in_progress = True
@@ -201,6 +207,8 @@ async def get_iter(self, decode: bool | None = None) -> AsyncIterator[Data]:
201207 :meth:`get_iter` concurrently.
202208
203209 """
210+ if self .cancelling :
211+ return
204212 if self .get_in_progress :
205213 raise ConcurrencyError ("get() or get_iter() is already running" )
206214 self .get_in_progress = True
@@ -251,6 +259,8 @@ def put(self, frame: Frame) -> None:
251259 EOFError: If the stream of frames has ended.
252260
253261 """
262+ if self .cancelling :
263+ return
254264 if self .closed :
255265 raise EOFError ("stream of frames ended" )
256266
@@ -283,7 +293,7 @@ def close(self) -> None:
283293 """
284294 End the stream of frames.
285295
286- Callling :meth:`close` concurrently with :meth:`get`, :meth:`get_iter`,
296+ Calling :meth:`close` concurrently with :meth:`get`, :meth:`get_iter`,
287297 or :meth:`put` is safe. They will raise :exc:`EOFError`.
288298
289299 """
0 commit comments