From 5d6ae81719f653095eab7edf478918b86f2d313e Mon Sep 17 00:00:00 2001 From: Daofeng Wu Date: Wed, 25 Dec 2024 19:38:16 +0900 Subject: [PATCH] fix(utils/concurrent_task_runner): error handling --- .../email_organizer/__test__/invoice_organizer.py | 3 --- npiai/utils/concurrent_task_runner.py | 10 +++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/npiai/tools/email_organizer/__test__/invoice_organizer.py b/npiai/tools/email_organizer/__test__/invoice_organizer.py index bf785e9..5b914de 100644 --- a/npiai/tools/email_organizer/__test__/invoice_organizer.py +++ b/npiai/tools/email_organizer/__test__/invoice_organizer.py @@ -17,9 +17,6 @@ async def main(): async with EmailOrganizer(provider=Outlook(creds)) as tool: email_list = [email async for email in tool.list_inbox_stream(limit=10)] - for email in email_list: - print(await tool._to_compact_email_with_pdf_attachments(email)) - print("Raw email list:", json.dumps(email_list, indent=4, ensure_ascii=False)) filtered_emails = [] diff --git a/npiai/utils/concurrent_task_runner.py b/npiai/utils/concurrent_task_runner.py index 499a824..1c3385c 100644 --- a/npiai/utils/concurrent_task_runner.py +++ b/npiai/utils/concurrent_task_runner.py @@ -1,4 +1,6 @@ import asyncio +import sys +import traceback from typing import Callable, Awaitable, Any, AsyncGenerator @@ -16,7 +18,13 @@ async def concurrent_task_runner[ counter_lock = asyncio.Lock() async def process(): - await fn(results_queue) + try: + await fn(results_queue) + except Exception: + print( + f"Error in concurrent_task_runner: {traceback.format_exc()}", + file=sys.stderr, + ) async def task_runner(): nonlocal running_task_count