Skip to content
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

Python 异步转同步报错记录 #19

Open
licoded opened this issue Aug 2, 2021 · 0 comments
Open

Python 异步转同步报错记录 #19

licoded opened this issue Aug 2, 2021 · 0 comments

Comments

@licoded
Copy link
Owner

licoded commented Aug 2, 2021

使用 bilibili-api 库 时按照 文档:同步执行异步代码 编写了如下代码

from bilibili_api import sync
from bilibili_api.favorite_list import get_video_favorite_list, get_video_favorite_list_content

favorite_list = sync(get_video_favorite_list(uid=uid, credential=credential))
    list = favorite_list['list']
    for i in range(len(list)):
        favorite = list[i]
        favorite['list'] = sync(get_video_favorite_list_content(media_id=favorite['id']))

产生报错 RuntimeError: There is no current event loop in thread 'Thread-14'

经检查,当在 Flask 换将中使用上述代码才会报错,单独使用这段代码是没有问题的。

最后问题也没有解决,经过搜索发现 Python 异步的风评比较差,就更换了 Puppeteer 来做爬虫
但其实离线同步数据到数据库也可以满足我的需求,但确实不优美

@licoded licoded added this to the 随手记录 milestone Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant