Skip to content

Commit c9c8f11

Browse files
committed
increase compability with jupyter
1 parent 188d8af commit c9c8f11

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

i2_client/client.py

Lines changed: 8 additions & 1 deletion
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,10 @@ async def _inference(self, inputs):
204205
await self.__aexit__(exc_type=None, exc_value=None, traceback=None)
205206
return outputs
206207

207-
return asyncio.run(_inference(self, inputs))
208+
loop = asyncio.get_running_loop()
209+
if loop.is_running():
210+
# when executed in jupyter notebook or something
211+
nest_asyncio.apply(loop)
212+
outputs = asyncio.run(_inference(self, inputs))
213+
214+
return outputs

0 commit comments

Comments
 (0)