Skip to content

Commit

Permalink
Merge pull request #51 from canvas-medical/csande/protocol-executor
Browse files Browse the repository at this point in the history
Run Protocol compute method in a threadpool to avoid blocking the main event loop
  • Loading branch information
csande authored May 31, 2024
2 parents 5861e65 + aa320f4 commit 6ebf1da
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions plugin_runner/plugin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import signal
import sys
import traceback

from collections import defaultdict

import grpc
from plugin_synchronizer import publish_message
from sandbox import Sandbox

from canvas_sdk.events import Event, EventResponse, EventType
Expand All @@ -20,8 +20,6 @@
)
from logger import log

from plugin_synchronizer import publish_message

ENV = os.getenv("ENV", "development")

IS_PRODUCTION = ENV == "production"
Expand Down Expand Up @@ -62,7 +60,8 @@ async def HandleEvent(self, request: Event, context):
protocol_class = plugin["class"]

try:
effects = protocol_class(request, plugin.get("secrets", {})).compute()
protocol = protocol_class(request, plugin.get("secrets", {}))
effects = await asyncio.get_running_loop().run_in_executor(None, protocol.compute)
except Exception as e:
log.error(traceback.format_exception(e))
continue
Expand Down

0 comments on commit 6ebf1da

Please sign in to comment.