Fix timeout
This commit is contained in:
parent
b89c7cb32d
commit
baefd09f65
12
redditbot.py
12
redditbot.py
|
@ -95,13 +95,16 @@ async def main():
|
|||
show_spoilers_warning = chat_data['show_spoilers_warning']
|
||||
timeout = chat_data.get('timeout')
|
||||
|
||||
def _get_submission_blocc():
|
||||
while True:
|
||||
give_ups = set()
|
||||
def _get_submission_blocc(unique_id):
|
||||
while unique_id not in give_ups:
|
||||
subreddit = reddit.subreddit(random.choice(subreddits))
|
||||
random_post = subreddit.random()
|
||||
cpid = cpp = None
|
||||
if random_post is None:
|
||||
for submission in subreddit.hot():
|
||||
if unique_id in give_ups:
|
||||
return
|
||||
cpid = getattr(submission, 'crosspost_parent', None)
|
||||
if cpid and getattr(random_post, 'crosspost_parent_list', None):
|
||||
cpid = cpid[3:]
|
||||
|
@ -158,14 +161,17 @@ async def main():
|
|||
@aiocron.crontab(cron_duration)
|
||||
async def start_post():
|
||||
while True:
|
||||
unique_id = time.time()
|
||||
try:
|
||||
random_post, cpp = await asyncio.wait_for(client.loop.run_in_executor(None, _get_submission_blocc), timeout)
|
||||
random_post, cpp = await asyncio.wait_for(client.loop.run_in_executor(None, _get_submission_blocc, unique_id), timeout)
|
||||
except asyncio.TimeoutError:
|
||||
give_ups.add(unique_id)
|
||||
logging.error('%s timed out', chat)
|
||||
for i in bot_admins:
|
||||
await client.send_message(i, f'{chat} timed out')
|
||||
break
|
||||
except Exception:
|
||||
give_ups.add(unique_id)
|
||||
logging.exception(chat)
|
||||
for i in bot_admins:
|
||||
await client.send_message(i, f'{chat}\n{traceback.format_exc()}')
|
||||
|
|
Loading…
Reference in New Issue