RuntimeError Traceback (most recent call last)…
- User
RuntimeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_19600/3914925488.py in 50 51 # Запуск асинхронной функции ---> 52 asyncio.run(main()) 53 print(datetime.now())
C:\Anaconda3\lib\asyncio\runners.py in run(main, debug) 31 """ 32 if events._get_running_loop() is not None: ---> 33 raise RuntimeError( 34 "asyncio.run() cannot be called from a running event loop") 35
RuntimeError: asyncio.run() cannot be called from a running event loop
- Assistant
The error you're encountering,
RuntimeError: asyncio.run() cannot be called from a running event loop, occurs whenasyncio.run()is called while there's already an active event loop. This commonly happens in environments like Jupyter notebooks or IPython, where an event loop is already running.To work around this issue, you can modify your code to use
awaitdirectly or usenest_asyncioto allow nested event loops. Here are a couple of approaches:Approach 1: Using
awaitdirectlyIf you're in an environment with an active event loop, you can just define your async function and call it with
awaitinstead ofasyncio.run().Here's how you can do it:
import asyncio async def main(): # Your asynchronous code here pass # If running in an interactive environment, use this: await main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.