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

AsyncModalDagExecutor raises when run from a jupyter notebook #162

Closed
TomNicholas opened this issue May 4, 2023 · 1 comment · Fixed by #661
Closed

AsyncModalDagExecutor raises when run from a jupyter notebook #162

TomNicholas opened this issue May 4, 2023 · 1 comment · Fixed by #661

Comments

@TomNicholas
Copy link
Member

Screenshot from 2023-05-04 16-00-19

returns

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /tmp/ipykernel_495009/1422487590.py:1 in <module>                                                │
│                                                                                                  │
│                                                                                                  │
│ /home/tom/Documents/Work/Code/cubed/cubed/core/array.py:112 in compute                           │
│                                                                                                  │
│   111 │   │   """Compute this array, and any arrays that it depends on."""                       │
│ ❱ 112 │   │   result = compute(                                                                  │
│   113 │   │   │   self,                                                                          │
│                                                                                                  │
│ /home/tom/Documents/Work/Code/cubed/cubed/core/array.py:300 in compute                           │
│                                                                                                  │
│   299_return_in_memory_array = kwargs.pop("_return_in_memory_array", True)                  │
│ ❱ 300plan.execute(                                                                          │
│   301 │   │   executor=executor,                                                                 │
│                                                                                                  │
│ /home/tom/Documents/Work/Code/cubed/cubed/core/plan.py:154 in execute                            │
│                                                                                                  │
│   153 │   │   │   │   [callback.on_compute_start(dag) for callback in callbacks]                 │
│ ❱ 154 │   │   │   executor.execute_dag(                                                          │
│   155 │   │   │   │   dag, callbacks=callbacks, array_names=array_names, **kwargs                │
│                                                                                                  │
│ /home/tom/Documents/Work/Code/cubed/cubed/runtime/executors/modal_async.py:178 in execute_dag    │
│                                                                                                  │
│   177def execute_dag(self, dag, callbacks=None, array_names=None, **kwargs):                │
│ ❱ 178 │   │   asyncio.run(                                                                       │
│   179 │   │   │   async_execute_dag(                                                             │
│                                                                                                  │
│ /home/tom/miniconda3/envs/cubed/lib/python3.9/asyncio/runners.py:33 in run                       │
│                                                                                                  │
│   32if events._get_running_loop() is not None:                                              │
│ ❱ 33 │   │   raise RuntimeError(                                                                 │
│   34 │   │   │   "asyncio.run() cannot be called from a running event loop")                     │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: asyncio.run() cannot be called from a running event loop

This SO answer seems to suggest that this could be fixed by changing this line in the executor

https://github.com/tomwhite/cubed/blob/74145fb826d21496ca86b4e64b0fcb1c55d8a931/cubed/runtime/executors/modal_async.py#L178

@tomwhite
Copy link
Member

tomwhite commented May 5, 2023

I tried some of the suggestions from the SO page, but then I get RuntimeWarning: coroutine 'async_execute_dag' was never awaited, and can't see an obvious way to avoid it.

It looks like the easiest fix may be to use nest_asyncio by putting the following at the top of the notebook:

import nest_asyncio
nest_asyncio.apply()

What do you think?

BTW AsyncPythonDagExecutor has the same problem and is useful for reproducing without using Modal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants