@@ -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" )
@@ -635,7 +635,7 @@ async def close(self, code: int = 1000, reason: str = "") -> None:
635
635
# The context manager takes care of waiting for the TCP connection
636
636
# to terminate after calling a method that sends a close frame.
637
637
async with self .send_context ():
638
- if self .fragmented_send_waiter is not None :
638
+ if self .send_in_progress is not None :
639
639
self .protocol .fail (
640
640
CloseCode .INTERNAL_ERROR ,
641
641
"close during fragmented message" ,
@@ -677,9 +677,9 @@ async def ping(self, data: Data | None = None) -> Awaitable[float]:
677
677
678
678
::
679
679
680
- pong_waiter = await ws.ping()
680
+ pong_received = await ws.ping()
681
681
# only if you want to wait for the corresponding pong
682
- latency = await pong_waiter
682
+ latency = await pong_received
683
683
684
684
Raises:
685
685
ConnectionClosed: When the connection is closed.
@@ -696,19 +696,19 @@ async def ping(self, data: Data | None = None) -> Awaitable[float]:
696
696
697
697
async with self .send_context ():
698
698
# Protect against duplicates if a payload is explicitly set.
699
- if data in self .pong_waiters :
699
+ if data in self .pending_pings :
700
700
raise ConcurrencyError ("already waiting for a pong with the same data" )
701
701
702
702
# Generate a unique random payload otherwise.
703
- while data is None or data in self .pong_waiters :
703
+ while data is None or data in self .pending_pings :
704
704
data = struct .pack ("!I" , random .getrandbits (32 ))
705
705
706
- pong_waiter = self .loop .create_future ()
706
+ pong_received = self .loop .create_future ()
707
707
# The event loop's default clock is time.monotonic(). Its resolution
708
708
# is a bit low on Windows (~16ms). This is improved in Python 3.13.
709
- self .pong_waiters [data ] = (pong_waiter , self .loop .time ())
709
+ self .pending_pings [data ] = (pong_received , self .loop .time ())
710
710
self .protocol .send_ping (data )
711
- return pong_waiter
711
+ return pong_received
712
712
713
713
async def pong (self , data : Data = b"" ) -> None :
714
714
"""
@@ -757,7 +757,7 @@ def acknowledge_pings(self, data: bytes) -> None:
757
757
758
758
"""
759
759
# Ignore unsolicited pong.
760
- if data not in self .pong_waiters :
760
+ if data not in self .pending_pings :
761
761
return
762
762
763
763
pong_timestamp = self .loop .time ()
@@ -766,20 +766,20 @@ def acknowledge_pings(self, data: bytes) -> None:
766
766
# Acknowledge all previous pings too in that case.
767
767
ping_id = None
768
768
ping_ids = []
769
- for ping_id , (pong_waiter , ping_timestamp ) in self .pong_waiters .items ():
769
+ for ping_id , (pong_received , ping_timestamp ) in self .pending_pings .items ():
770
770
ping_ids .append (ping_id )
771
771
latency = pong_timestamp - ping_timestamp
772
- if not pong_waiter .done ():
773
- pong_waiter .set_result (latency )
772
+ if not pong_received .done ():
773
+ pong_received .set_result (latency )
774
774
if ping_id == data :
775
775
self .latency = latency
776
776
break
777
777
else :
778
778
raise AssertionError ("solicited pong not found in pings" )
779
779
780
- # Remove acknowledged pings from self.pong_waiters .
780
+ # Remove acknowledged pings from self.pending_pings .
781
781
for ping_id in ping_ids :
782
- del self .pong_waiters [ping_id ]
782
+ del self .pending_pings [ping_id ]
783
783
784
784
def abort_pings (self ) -> None :
785
785
"""
@@ -791,16 +791,16 @@ def abort_pings(self) -> None:
791
791
assert self .protocol .state is CLOSED
792
792
exc = self .protocol .close_exc
793
793
794
- for pong_waiter , _ping_timestamp in self .pong_waiters .values ():
795
- if not pong_waiter .done ():
796
- pong_waiter .set_exception (exc )
794
+ for pong_received , _ping_timestamp in self .pending_pings .values ():
795
+ if not pong_received .done ():
796
+ pong_received .set_exception (exc )
797
797
# If the exception is never retrieved, it will be logged when ping
798
798
# is garbage-collected. This is confusing for users.
799
799
# Given that ping is done (with an exception), canceling it does
800
800
# nothing, but it prevents logging the exception.
801
- pong_waiter .cancel ()
801
+ pong_received .cancel ()
802
802
803
- self .pong_waiters .clear ()
803
+ self .pending_pings .clear ()
804
804
805
805
async def keepalive (self ) -> None :
806
806
"""
@@ -821,7 +821,7 @@ async def keepalive(self) -> None:
821
821
# connection to be closed before raising ConnectionClosed.
822
822
# However, connection_lost() cancels keepalive_task before
823
823
# it gets a chance to resume excuting.
824
- pong_waiter = await self .ping ()
824
+ pong_received = await self .ping ()
825
825
if self .debug :
826
826
self .logger .debug ("% sent keepalive ping" )
827
827
@@ -830,9 +830,9 @@ async def keepalive(self) -> None:
830
830
async with asyncio_timeout (self .ping_timeout ):
831
831
# connection_lost cancels keepalive immediately
832
832
# after setting a ConnectionClosed exception on
833
- # pong_waiter . A CancelledError is raised here,
833
+ # pong_received . A CancelledError is raised here,
834
834
# not a ConnectionClosed exception.
835
- latency = await pong_waiter
835
+ latency = await pong_received
836
836
self .logger .debug ("% received keepalive pong" )
837
837
except asyncio .TimeoutError :
838
838
if self .debug :
@@ -1201,7 +1201,7 @@ def broadcast(
1201
1201
if connection .protocol .state is not OPEN :
1202
1202
continue
1203
1203
1204
- if connection .fragmented_send_waiter is not None :
1204
+ if connection .send_in_progress is not None :
1205
1205
if raise_exceptions :
1206
1206
exception = ConcurrencyError ("sending a fragmented message" )
1207
1207
exceptions .append (exception )
0 commit comments