Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve RuntimeError for missing event loop in AnyIO worker thread #275

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/backend/app/projects/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from loguru import logger as log
from concurrent.futures import ThreadPoolExecutor
from psycopg import Connection
import asyncio
from asgiref.sync import async_to_sync


class DroneImageProcessor:
Expand Down Expand Up @@ -158,18 +158,18 @@ def process_images_from_s3(self, bucket_name, name=None, options=[]):
add_file_to_bucket(bucket_name, path_to_download, s3_path)
# now update the task as completed in Db.
# Call the async function using asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(
task_logic.update_task_state(
self.db,
self.project_id,
self.task_id,
self.user_id,
"Task completed.",
State.IMAGE_UPLOADED,
State.IMAGE_PROCESSED,
timestamp(),
)

# Update background task status to COMPLETED
update_task_status_sync = async_to_sync(task_logic.update_task_state)
update_task_status_sync(
self.db,
self.project_id,
self.task_id,
self.user_id,
"Task completed.",
State.IMAGE_UPLOADED,
State.IMAGE_PROCESSED,
timestamp(),
)
return task

Expand Down
Loading