@@ -70,17 +70,17 @@ def getdefaulttimeout() -> Optional[float]:
70
70
return _default_socket_timeout
71
71
72
72
73
- def setdefaulttimeout (timeout : Optional [float ]) -> None :
73
+ def setdefaulttimeout (_timeout : Optional [float ]) -> None :
74
74
"""
75
75
Set the default timeout in seconds (float) for new socket objects. When the socket
76
76
module is first imported, the default is None. See settimeout() for possible values
77
77
and their respective meanings.
78
78
79
- :param Optional[float] timeout : The default timeout in seconds or None.
79
+ :param Optional[float] _timeout : The default timeout in seconds or None.
80
80
"""
81
81
global _default_socket_timeout # pylint: disable=global-statement
82
- if timeout is None or (isinstance (timeout , (int , float )) and timeout >= 0 ):
83
- _default_socket_timeout = timeout
82
+ if _timeout is None or (isinstance (_timeout , (int , float )) and _timeout >= 0 ):
83
+ _default_socket_timeout = _timeout
84
84
else :
85
85
raise ValueError ("Timeout must be None, 0.0 or a positive numeric value." )
86
86
@@ -450,8 +450,8 @@ def send(self, data: Union[bytes, bytearray]) -> int:
450
450
451
451
:return int: Number of bytes sent.
452
452
"""
453
- timeout = 0 if self ._timeout is None else self ._timeout
454
- bytes_sent = _the_interface .socket_write (self ._socknum , data , timeout )
453
+ _timeout = 0 if self ._timeout is None else self ._timeout
454
+ bytes_sent = _the_interface .socket_write (self ._socknum , data , _timeout )
455
455
gc .collect ()
456
456
return bytes_sent
457
457
@@ -498,7 +498,7 @@ def recv(
498
498
stamp = time .monotonic ()
499
499
while not self ._available ():
500
500
if self ._timeout and 0 < self ._timeout < time .monotonic () - stamp :
501
- break
501
+ raise timeout ( "timed out" )
502
502
time .sleep (0.05 )
503
503
bytes_on_socket = self ._available ()
504
504
if not bytes_on_socket :
@@ -730,3 +730,11 @@ def type(self):
730
730
def proto (self ):
731
731
"""Socket protocol (always 0x00 in this implementation)."""
732
732
return 0
733
+
734
+
735
+ class timeout (TimeoutError ):
736
+ """TimeoutError class. An instance of this error will be raised by recv_into() if
737
+ the timeout has elapsed and we haven't received any data yet."""
738
+
739
+ def __init__ (self , msg ):
740
+ super ().__init__ (msg )
0 commit comments