Skip to content

Commit

Permalink
add support for executing operators in notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor committed Mar 7, 2024
1 parent a1c2909 commit 5b0022b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions fiftyone/operators/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5b0022b

Please sign in to comment.