Skip to content

Commit

Permalink
fix: no hard dependency on nest_asyncio, use only when needed.
Browse files Browse the repository at this point in the history
Only when we have a current event loop do we need nest_asyncio to be
used and installed. In case where readinto is called from a thread
(this is something we do in solara) which does not have an event loop
yet, we should not need nest_asyncio.

When needed, and not installed, we raise an error with an informative
installation instruction.
  • Loading branch information
maartenbreddels committed Apr 5, 2024
1 parent 778deaa commit 9edc0a6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ipyvuetify/extra/file_input.py
Expand Up @@ -5,7 +5,14 @@
import sys

import IPython
import nest_asyncio

try:
import nest_asyncio

has_nest_asyncio = True
except ModuleNotFoundError:
has_nest_asyncio = False

import traitlets

import ipyvuetify as v
Expand Down Expand Up @@ -173,7 +180,12 @@ def __init__(self, **kwargs):
return
kernel = IPython.get_ipython().kernel
if kernel.implementation == "ipython":
nest_asyncio.apply()
if not has_nest_asyncio:
raise RuntimeError(
"nest_asyncio is required for FileInput in IPython kernel, please run 'pip install nest_asyncio'"
)
else:
nest_asyncio.apply()

@traitlets.observe("file_info")
def _file_info_changed(self, _):
Expand Down

0 comments on commit 9edc0a6

Please sign in to comment.