Skip to content

Commit

Permalink
Timeout asyncify'd pyinat requests after 20 seconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
synrg committed Oct 16, 2024
1 parent dfbcc57 commit 0f522ba
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion inatcog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import partial
from typing import Optional, Union

import asyncio
import discord
from dronefly.core.clients.inat import iNatClient as CoreiNatClient
from dronefly.core.commands import Context as DroneflyContext
Expand All @@ -12,7 +13,11 @@

def asyncify(self, method):
async def async_wrapper(*args, **kwargs):
return await self.loop.run_in_executor(None, partial(method, *args, **kwargs))
future = self.loop.run_in_executor(None, partial(method, *args, **kwargs))
try:
return await asyncio.wait_for(future, timeout=20)
except TimeoutError:
raise LookupError("iNaturalist API request timed out")

return async_wrapper

Expand Down

0 comments on commit 0f522ba

Please sign in to comment.