@@ -101,10 +101,10 @@ def __init__(
101
101
self .close_deadline : float | None = None
102
102
103
103
# Protect sending fragmented messages.
104
- self .fragmented_send_waiter : asyncio .Future [None ] | None = None
104
+ self .send_in_progress : asyncio .Future [None ] | None = None
105
105
106
106
# Mapping of ping IDs to pong waiters, in chronological order.
107
- self .pong_waiters : dict [bytes , tuple [asyncio .Future [float ], float ]] = {}
107
+ self .pending_pings : dict [bytes , tuple [asyncio .Future [float ], float ]] = {}
108
108
109
109
self .latency : float = 0
110
110
"""
@@ -468,8 +468,8 @@ async def send(
468
468
"""
469
469
# While sending a fragmented message, prevent sending other messages
470
470
# until all fragments are sent.
471
- while self .fragmented_send_waiter is not None :
472
- await asyncio .shield (self .fragmented_send_waiter )
471
+ while self .send_in_progress is not None :
472
+ await asyncio .shield (self .send_in_progress )
473
473
474
474
# Unfragmented message -- this case must be handled first because
475
475
# strings and bytes-like objects are iterable.
@@ -502,8 +502,8 @@ async def send(
502
502
except StopIteration :
503
503
return
504
504
505
- assert self .fragmented_send_waiter is None
506
- self .fragmented_send_waiter = self .loop .create_future ()
505
+ assert self .send_in_progress is None
506
+ self .send_in_progress = self .loop .create_future ()
507
507
try :
508
508
# First fragment.
509
509
if isinstance (chunk , str ):
@@ -549,8 +549,8 @@ async def send(
549
549
raise
550
550
551
551
finally :
552
- self .fragmented_send_waiter .set_result (None )
553
- self .fragmented_send_waiter = None
552
+ self .send_in_progress .set_result (None )
553
+ self .send_in_progress = None
554
554
555
555
# Fragmented message -- async iterator.
556
556
@@ -561,8 +561,8 @@ async def send(
561
561
except StopAsyncIteration :
562
562
return
563
563
564
- assert self .fragmented_send_waiter is None
565
- self .fragmented_send_waiter = self .loop .create_future ()
564
+ assert self .send_in_progress is None
565
+ self .send_in_progress = self .loop .create_future ()
566
566
try :
567
567
# First fragment.
568
568
if isinstance (chunk , str ):
@@ -610,8 +610,8 @@ async def send(
610
610
raise
611
611
612
612
finally :
613
- self .fragmented_send_waiter .set_result (None )
614
- self .fragmented_send_waiter = None
613
+ self .send_in_progress .set_result (None )
614
+ self .send_in_progress = None
615
615
616
616
else :
617
617
raise TypeError ("data must be str, bytes, iterable, or async iterable" )
@@ -639,7 +639,7 @@ async def close(
639
639
# The context manager takes care of waiting for the TCP connection
640
640
# to terminate after calling a method that sends a close frame.
641
641
async with self .send_context ():
642
- if self .fragmented_send_waiter is not None :
642
+ if self .send_in_progress is not None :
643
643
self .protocol .fail (
644
644
CloseCode .INTERNAL_ERROR ,
645
645
"close during fragmented message" ,
@@ -681,9 +681,9 @@ async def ping(self, data: DataLike | None = None) -> Awaitable[float]:
681
681
682
682
::
683
683
684
- pong_waiter = await ws.ping()
684
+ pong_received = await ws.ping()
685
685
# only if you want to wait for the corresponding pong
686
- latency = await pong_waiter
686
+ latency = await pong_received
687
687
688
688
Raises:
689
689
ConnectionClosed: When the connection is closed.
@@ -700,19 +700,19 @@ async def ping(self, data: DataLike | None = None) -> Awaitable[float]:
700
700
701
701
async with self .send_context ():
702
702
# Protect against duplicates if a payload is explicitly set.
703
- if data in self .pong_waiters :
703
+ if data in self .pending_pings :
704
704
raise ConcurrencyError ("already waiting for a pong with the same data" )
705
705
706
706
# Generate a unique random payload otherwise.
707
- while data is None or data in self .pong_waiters :
707
+ while data is None or data in self .pending_pings :
708
708
data = struct .pack ("!I" , random .getrandbits (32 ))
709
709
710
- pong_waiter = self .loop .create_future ()
710
+ pong_received = self .loop .create_future ()
711
711
# The event loop's default clock is time.monotonic(). Its resolution
712
712
# is a bit low on Windows (~16ms). This is improved in Python 3.13.
713
- self .pong_waiters [data ] = (pong_waiter , self .loop .time ())
713
+ self .pending_pings [data ] = (pong_received , self .loop .time ())
714
714
self .protocol .send_ping (data )
715
- return pong_waiter
715
+ return pong_received
716
716
717
717
async def pong (self , data : DataLike = b"" ) -> None :
718
718
"""
@@ -761,7 +761,7 @@ def acknowledge_pings(self, data: bytes) -> None:
761
761
762
762
"""
763
763
# Ignore unsolicited pong.
764
- if data not in self .pong_waiters :
764
+ if data not in self .pending_pings :
765
765
return
766
766
767
767
pong_timestamp = self .loop .time ()
@@ -770,20 +770,20 @@ def acknowledge_pings(self, data: bytes) -> None:
770
770
# Acknowledge all previous pings too in that case.
771
771
ping_id = None
772
772
ping_ids = []
773
- for ping_id , (pong_waiter , ping_timestamp ) in self .pong_waiters .items ():
773
+ for ping_id , (pong_received , ping_timestamp ) in self .pending_pings .items ():
774
774
ping_ids .append (ping_id )
775
775
latency = pong_timestamp - ping_timestamp
776
- if not pong_waiter .done ():
777
- pong_waiter .set_result (latency )
776
+ if not pong_received .done ():
777
+ pong_received .set_result (latency )
778
778
if ping_id == data :
779
779
self .latency = latency
780
780
break
781
781
else :
782
782
raise AssertionError ("solicited pong not found in pings" )
783
783
784
- # Remove acknowledged pings from self.pong_waiters .
784
+ # Remove acknowledged pings from self.pending_pings .
785
785
for ping_id in ping_ids :
786
- del self .pong_waiters [ping_id ]
786
+ del self .pending_pings [ping_id ]
787
787
788
788
def abort_pings (self ) -> None :
789
789
"""
@@ -795,16 +795,16 @@ def abort_pings(self) -> None:
795
795
assert self .protocol .state is CLOSED
796
796
exc = self .protocol .close_exc
797
797
798
- for pong_waiter , _ping_timestamp in self .pong_waiters .values ():
799
- if not pong_waiter .done ():
800
- pong_waiter .set_exception (exc )
798
+ for pong_received , _ping_timestamp in self .pending_pings .values ():
799
+ if not pong_received .done ():
800
+ pong_received .set_exception (exc )
801
801
# If the exception is never retrieved, it will be logged when ping
802
802
# is garbage-collected. This is confusing for users.
803
803
# Given that ping is done (with an exception), canceling it does
804
804
# nothing, but it prevents logging the exception.
805
- pong_waiter .cancel ()
805
+ pong_received .cancel ()
806
806
807
- self .pong_waiters .clear ()
807
+ self .pending_pings .clear ()
808
808
809
809
async def keepalive (self ) -> None :
810
810
"""
@@ -825,7 +825,7 @@ async def keepalive(self) -> None:
825
825
# connection to be closed before raising ConnectionClosed.
826
826
# However, connection_lost() cancels keepalive_task before
827
827
# it gets a chance to resume excuting.
828
- pong_waiter = await self .ping ()
828
+ pong_received = await self .ping ()
829
829
if self .debug :
830
830
self .logger .debug ("% sent keepalive ping" )
831
831
@@ -834,9 +834,9 @@ async def keepalive(self) -> None:
834
834
async with asyncio_timeout (self .ping_timeout ):
835
835
# connection_lost cancels keepalive immediately
836
836
# after setting a ConnectionClosed exception on
837
- # pong_waiter . A CancelledError is raised here,
837
+ # pong_received . A CancelledError is raised here,
838
838
# not a ConnectionClosed exception.
839
- latency = await pong_waiter
839
+ latency = await pong_received
840
840
self .logger .debug ("% received keepalive pong" )
841
841
except asyncio .TimeoutError :
842
842
if self .debug :
@@ -1205,7 +1205,7 @@ def broadcast(
1205
1205
if connection .protocol .state is not OPEN :
1206
1206
continue
1207
1207
1208
- if connection .fragmented_send_waiter is not None :
1208
+ if connection .send_in_progress is not None :
1209
1209
if raise_exceptions :
1210
1210
exception = ConcurrencyError ("sending a fragmented message" )
1211
1211
exceptions .append (exception )
0 commit comments