-
Notifications
You must be signed in to change notification settings - Fork 222
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
sync函数近期更改,该如何调用? #860
Labels
question
这啥呀这是,我不到啊
Comments
我改的。当时没有测试linux环境。这个应该是sync函数的bug。能看一下具体的报错信息吗?能不能把完整的报错信息截图发出来 |
其中roomInfos[room_id]['live_danmaku'] 是一个LiveDanmaku类 |
报错信息为:
使用改之前的sync()版本就不会报错 |
不是很懂为什么会这样。理论上这行代码引发错误会被捕获。 如果只想解决问题,可以试试使用asyncio.run(coroutine)代替sync(coroutine) def sync(coroutine: Coroutine) -> Any:
"""
同步执行异步函数,使用可参考 [同步执行异步代码](https://nemo2011.github.io/bilibili-api/#/sync-executor)
Args:
coroutine (Coroutine): 执行异步函数所创建的协程对象
Returns:
该协程对象的返回值
"""
try:
asyncio.get_running_loop()
except RuntimeError:
return asyncio.run(coroutine)
else:
with ThreadPoolExecutor() as executor:
return executor.submit(asyncio.run, coroutine).result() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python 版本: 3.11.10
模块版本: 可用版本:16.1.1 报错版本:16.3.0
运行环境: Linux
我在16.1.1版本时可以这么使用sync:
更新到16.3.0之后会报错sync 22行:
no running event loop
看起来16.1.1与16.3.0之间sync进行了比较大的改变。请问现在该如何正确使用呢?
The text was updated successfully, but these errors were encountered: