1313SSE_EVENT_MESSAGE = 'message'
1414_DEFAULT_HEADERS = {'accept' : 'text/event-stream' }
1515_EVENT_SEPARATORS = set ([b'\n ' , b'\r \n ' ])
16- _DEFAULT_ASYNC_TIMEOUT = 300
16+ _DEFAULT_SOCKET_READ_TIMEOUT = 70
1717
1818SSEEvent = namedtuple ('SSEEvent' , ['event_id' , 'event' , 'retry' , 'data' ])
1919
@@ -139,7 +139,7 @@ def shutdown(self):
139139class SSEClientAsync (object ):
140140 """SSE Client implementation."""
141141
142- def __init__ (self , timeout = _DEFAULT_ASYNC_TIMEOUT ):
142+ def __init__ (self , socket_read_timeout = _DEFAULT_SOCKET_READ_TIMEOUT ):
143143 """
144144 Construct an SSE client.
145145
@@ -152,7 +152,7 @@ def __init__(self, timeout=_DEFAULT_ASYNC_TIMEOUT):
152152 :param timeout: connection & read timeout
153153 :type timeout: float
154154 """
155- self ._timeout = timeout
155+ self ._socket_read_timeout = socket_read_timeout + socket_read_timeout * .3
156156 self ._response = None
157157 self ._done = asyncio .Event ()
158158
@@ -168,7 +168,8 @@ async def start(self, url, extra_headers=None): # pylint:disable=protected-acce
168168 raise RuntimeError ('Client already started.' )
169169
170170 self ._done .clear ()
171- async with aiohttp .ClientSession () as sess :
171+ client_timeout = aiohttp .ClientTimeout (total = 0 , sock_read = self ._socket_read_timeout )
172+ async with aiohttp .ClientSession (timeout = client_timeout ) as sess :
172173 try :
173174 async with sess .get (url , headers = get_headers (extra_headers )) as response :
174175 self ._response = response
0 commit comments