Skip to content

Commit 436c4ce

Browse files
committed
increase compability with jupyter
1 parent 6028900 commit 436c4ce

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

i2_client/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import archipel_utils as utils
1515
import msgpack
16+
import nest_asyncio
1617
import websockets
1718

1819
log = logging.getLogger(__name__)
@@ -204,4 +205,12 @@ async def _inference(self, inputs):
204205
await self.__aexit__(exc_type=None, exc_value=None, traceback=None)
205206
return outputs
206207

208+
try:
209+
loop = asyncio.get_running_loop()
210+
if loop.is_running():
211+
# when executed in jupyter notebook or something
212+
nest_asyncio.apply(loop)
213+
except RuntimeError:
214+
pass
215+
207216
return asyncio.run(_inference(self, inputs))

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"imutils>=0.5.4",
2626
"msgpack>=1.0",
2727
"numpy>=1.19",
28+
"nest-asyncio>=1.5",
2829
"rich>=10.13",
2930
"websockets>=8.1",
3031
"opencv-python==4.6.0.66",

0 commit comments

Comments
 (0)