Add ExitRequest raise while waiting for a server response
This commit is contained in:
1 parent
90fb6ea9a7
commit
aebd0e6570
1 file changed
+14
-1
@@ -870,7 +870,17 @@ class Twitch:
|
|||||||
logger.debug(f"Request: ({method=}, {url=}, {kwargs=})")
|
logger.debug(f"Request: ({method=}, {url=}, {kwargs=})")
|
||||||
for delay in ExponentialBackoff(shift=1, maximum=3*60):
|
for delay in ExponentialBackoff(shift=1, maximum=3*60):
|
||||||
try:
|
try:
|
||||||
async with session.request(method, url, **kwargs) as response:
|
response = None
|
||||||
|
done, pending = await asyncio.wait(
|
||||||
|
[session.request(method, url, **kwargs), self.gui.wait_until_closed()],
|
||||||
|
return_when=asyncio.FIRST_COMPLETED,
|
||||||
|
)
|
||||||
|
if self.gui.close_requested:
|
||||||
|
raise ExitRequest()
|
||||||
|
for task in done:
|
||||||
|
response = task.result()
|
||||||
|
break
|
||||||
|
if response is not None:
|
||||||
logger.debug(f"Response: {response.status}: {response}")
|
logger.debug(f"Response: {response.status}: {response}")
|
||||||
if response.status < 500:
|
if response.status < 500:
|
||||||
yield response
|
yield response
|
||||||
@@ -880,6 +890,9 @@ class Twitch:
|
|||||||
# just so that quick 2nd retries that often happen, aren't shown
|
# just so that quick 2nd retries that often happen, aren't shown
|
||||||
if delay > 1:
|
if delay > 1:
|
||||||
self.print(_("error", "no_connection").format(seconds=round(delay)))
|
self.print(_("error", "no_connection").format(seconds=round(delay)))
|
||||||
|
finally:
|
||||||
|
if response is not None:
|
||||||
|
response.release()
|
||||||
await asyncio.sleep(delay)
|
await asyncio.sleep(delay)
|
||||||
|
|
||||||
async def gql_request(self, op: GQLOperation) -> JsonType:
|
async def gql_request(self, op: GQLOperation) -> JsonType:
|
||||||
|
|||||||
Reference in new issue
Block a user