From 5b0022b23eabf05a86ab74d147cc7c2e9e58c3b9 Mon Sep 17 00:00:00 2001 From: brimoor Date: Thu, 7 Mar 2024 00:48:59 -0500 Subject: [PATCH] add support for executing operators in notebooks --- fiftyone/operators/executor.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fiftyone/operators/executor.py b/fiftyone/operators/executor.py index d7001fcbda..7fae44a52d 100644 --- a/fiftyone/operators/executor.py +++ b/fiftyone/operators/executor.py @@ -13,6 +13,7 @@ import traceback import fiftyone as fo +import fiftyone.core.context as foc import fiftyone.core.dataset as fod import fiftyone.core.odm.utils as focu import fiftyone.core.utils as fou @@ -146,12 +147,18 @@ def execute_operator(operator_uri, ctx=None, **kwargs): """ request_params = _parse_ctx(ctx=ctx, **kwargs) - result = asyncio.run( - execute_or_delegate_operator( - operator_uri, request_params, exhaust=True - ) + coroutine = execute_or_delegate_operator( + operator_uri, request_params, exhaust=True ) - result.raise_exceptions() + + if foc.is_notebook_context(): + # Notebooks already have event loops running, so we must execute there + loop = asyncio.get_event_loop() + loop.create_task(coroutine) + result = None # @todo can we await result here? + else: + result = asyncio.run(coroutine) + result.raise_exceptions() return result