python - while 循环中的 Spotipy 请求速度

标签 python python-3.x spotify spotipy

count = 0
while True:
        if count > 20:
                count = 0
                current_track = spotify.current_user_playing_track()
                if current_track is None:
                        display_string = ""
                else:
                        display_string = current_track['item']['name']+" - "+current_track['item']['artists'][0]['name']+" | "
                if display_string != previous_track:
                        sphd.clear()
                        sphd.write_string(display_string,brightness=0.1)
                        previous_track = display_string[:]
        time.sleep(0.05)
        sphd.show()
        sphd.scroll(1)
        count += 1

上面的代码在 Pi Zero 上运行,每秒获取当前播放的轨道并将其显示在 rollphathd 显示屏上。问题是,获取轨迹的过程导致显示卡住约 0.25 秒。有没有什么方法可以运行循环来单独获取轨道以刷新显示的滚动,或者有什么方法可以加快获取轨道的速度?感谢您提前提供的任何帮助。

最佳答案

卡住的原因可能是 Raspberry Pi Zero 的性能较低。

关于python - while 循环中的 Spotipy 请求速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49475395/

相关文章:

python - 如何将meshgrid的输出转换为对应的点数组?

python - 在 QtWidget 的 PyQt5 中按下角落里的红色 x 按钮时如何处理/覆盖?

ios - Spotify PKCE 授权流程返回 "code_verifier was incorrect"

linux - WINE Linux Debian Spotify 登录损坏

Spotify Web API - token 验证

python - 是否可以使用时间戳检查两个不同日期之间的日期和时间戳?

python - Pandas :拆分索引字符串并汇总相等切片的行

Python 函数参数不是深度复制

python-3.x - 如何在 Python 中使用类装饰器混合行为?

python - PyInstaller 无法包含图标