mirror of
https://github.com/rangermix/TwitchDropsMiner.git
synced 2026-06-03 10:59:37 +00:00
Add ExitRequest raise while waiting for a server response
This commit is contained in:
15
twitch.py
15
twitch.py
@@ -870,7 +870,17 @@ class Twitch:
|
||||
logger.debug(f"Request: ({method=}, {url=}, {kwargs=})")
|
||||
for delay in ExponentialBackoff(shift=1, maximum=3*60):
|
||||
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}")
|
||||
if response.status < 500:
|
||||
yield response
|
||||
@@ -880,6 +890,9 @@ class Twitch:
|
||||
# just so that quick 2nd retries that often happen, aren't shown
|
||||
if delay > 1:
|
||||
self.print(_("error", "no_connection").format(seconds=round(delay)))
|
||||
finally:
|
||||
if response is not None:
|
||||
response.release()
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
async def gql_request(self, op: GQLOperation) -> JsonType:
|
||||
|
||||
Reference in New Issue
Block a user