e2b-dev / code-interpreter

Python & JS/TS SDK for running AI-generated code/code interpreting in your AI app
https://e2b.dev
Apache License 2.0
1.28k stars 96 forks source link

conflict with `nest_asyncio` #11

Closed sudoskys closed 7 months ago

sudoskys commented 7 months ago
Exception ignored in: <async_generator object Connect.__aiter__ at 0x766b75501b40>
Traceback (most recent call last):
  File "/home//Project/Project/LlmKira/Openaibot/.venv/lib/python3.11/site-packages/e2b/sandbox/websocket_client.py", line 107, in _connect
Exception ignored in: <async_generator object Connect.__aiter__ at 0x766b75500940>
Traceback (most recent call last):
  File "/home//Project/Project/LlmKira/Openaibot/.venv/lib/python3.11/site-packages/e2b/sandbox/websocket_client.py", line 107, in _connect
    break
RuntimeError: async generator ignored GeneratorExit
    break
RuntimeError: async generator ignored GeneratorExit
import base64
import io

import nest_asyncio
from e2b_code_interpreter import CodeInterpreter

nest_asyncio.apply()
code = """
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 20, 100)
y = np.sin(x)

plt.plot(x, y)
plt.show()
"""

with CodeInterpreter() as sandbox:
    # you can install dependencies in "jupyter notebook style"
    sandbox.notebook.exec_cell("!pip install matplotlib")

    # plot random graph
    execution = sandbox.notebook.exec_cell(code)

# there's your image
image = execution.results[0].png

# example how to show the image / prove it works
i = base64.b64decode(image)
i = io.BytesIO(i)
with open("image.png", "wb") as f:
    f.write(i.read())
sudoskys commented 7 months ago

https://github.com/e2b-dev/E2B/issues/362

sudoskys commented 7 months ago

Solved by removing nest_asyncio