-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: This event loop is already running cause using jupyter as editor #30
Comments
你可以給我完整的程式碼嗎? 如果你是使用範例程式碼,請提供環境。 |
我是使用您提供的範例程式碼:(排版有點怪,不好意思) import asyncio from re_edge_gpt import Chatbot async def test_ask() -> None: if name == "main": 謝謝您的幫忙~ |
你把運行那段改成這樣呢?
|
C:\Users\USER\anaconda3\Lib\re_init_.py:258: RuntimeWarning: coroutine 'test_ask' was never awaited RuntimeError Traceback (most recent call last) File ~\anaconda3\Lib\asyncio\base_events.py:629, in BaseEventLoop.run_until_complete(self, future) File ~\anaconda3\Lib\asyncio\base_events.py:588, in BaseEventLoop._check_running(self) RuntimeError: This event loop is already running |
我裝 anaconda 看看,說不定是他的問題。 |
了解,謝謝您,還是您可以跟我說您是用什麼跑的,或是環境?非常感謝您! |
Pycharm 2023.1.4 |
好的,謝謝您~ |
我剛注意到 conda 好像不能抓到 package 或許你可以用 VSCode 跟 原生 Python pip 試試看。 |
除了 Conda install 抓不到package外,我用 Anaconda3 python3.9 是可以跑得。 |
如果你是採用 Jupyter 要注意他原本就有啟用 asyncio,你可能要額外 安裝 nest-asyncio |
我是使用Jupiter
JeffreyChen ***@***.***>於 2023年10月23日 週一,下午5:20寫道:
… 如果你是採用 Jupyter 要注意他原本就有啟用 asyncio,你可能要額外 安裝 nest-asyncio
並在開頭 nest_asyncio.apply()
—
Reply to this email directly, view it on GitHub
<#30 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A5VHBNHPKLZPJLKCGMITXGLYAYZF3AVCNFSM6AAAAAA6LWGHK6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUG43TCNBVGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
我再試試,有問題再問您,非常感謝您!
Yuki Lin ***@***.***>於 2023年10月23日 週一,下午5:23寫道:
… 我是使用Jupiter
JeffreyChen ***@***.***>於 2023年10月23日 週一,下午5:20寫道:
> 如果你是採用 Jupyter 要注意他原本就有啟用 asyncio,你可能要額外 安裝 nest-asyncio
> 並在開頭 nest_asyncio.apply()
>
> —
> Reply to this email directly, view it on GitHub
> <#30 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A5VHBNHPKLZPJLKCGMITXGLYAYZF3AVCNFSM6AAAAAA6LWGHK6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUG43TCNBVGQ>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
試試看這個使用 nest_asyncio 的,要記得安裝 nest_asyncio 套件! |
OK,appreciate that.
JeffreyChen ***@***.***>於 2023年10月23日 週一,下午5:26寫道:
… import asyncio
import json
from pathlib import Path
from nest_asyncio import apply
from re_edge_gpt import Chatbot
from re_edge_gpt import ConversationStyle
async def test_ask() -> None:
cookies = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)
response = await bot.ask(
prompt="find me some information about the new ai released by meta.",
conversation_style=ConversationStyle.balanced,
simplify_response=True,
)
await bot.close()
print(json.dumps(response, indent=2))
assert response
if __name__ == "__main__":
apply()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop()
loop.run_until_complete(test_ask())
試試看這個使用 nest_asyncio 的
—
Reply to this email directly, view it on GitHub
<#30 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A5VHBNEE3JE7C3CJOUFZFKTYAYZ27AVCNFSM6AAAAAA6LWGHK6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUG44DCMJUHE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
可以了~非常感謝您! |
也謝謝你,之前沒注意到這個問題,之後會寫在 README 跟 文件給人參考如何解決。 |
RuntimeError Traceback (most recent call last)
Cell In[10], line 25
23 if name == "main":
24 loop = asyncio.get_event_loop()
---> 25 loop.run_until_complete(test_ask())
File ~\anaconda3\Lib\asyncio\base_events.py:629, in BaseEventLoop.run_until_complete(self, future)
618 """Run until the Future is done.
619
620 If the argument is a coroutine, it is wrapped in a Task.
(...)
626 Return the Future's result, or raise its exception.
627 """
628 self._check_closed()
--> 629 self._check_running()
631 new_task = not futures.isfuture(future)
632 future = tasks.ensure_future(future, loop=self)
File ~\anaconda3\Lib\asyncio\base_events.py:588, in BaseEventLoop._check_running(self)
586 def _check_running(self):
587 if self.is_running():
--> 588 raise RuntimeError('This event loop is already running')
589 if events._get_running_loop() is not None:
590 raise RuntimeError(
591 'Cannot run the event loop while another loop is running')
RuntimeError: This event loop is already running
The text was updated successfully, but these errors were encountered: