You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python线程长时间等待后恢复致音乐应用崩溃问题求助

音乐应用暂停后长时间恢复偶发崩溃问题排查请求

暂停音乐后间隔较长时间(远超30秒)恢复,应用会偶发崩溃,崩溃概率约15%,暂未找到共性诱因。崩溃时抛出如下错误:

Exception in thread Thread-46 (resume):
Traceback (most recent call last):
File "C:\Users\my_name\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner

Process finished with exit code -1073741819 (0xC0000005)

触发崩溃的初始调用函数:

def resume_thread(self):
    self.is_playing = True
    self.thr = KThread(target=self.resume)
    self.thr.start()
    self.song_begin = time.time()

该函数通过线程调用resume方法,其余变量仅用于内部状态追踪,无关键影响。

resume方法实现及执行逻辑:

def resume(self):
    self.exited.clear()
    self.resume_list.append(self.pause_time)
    self.song_count -= 1
    new_time = 0
    self.controller.music_obj = self.current_playlist[self.song_count]
    self.song = AudioSegment.from_file(self.controller.music_obj.Savelocation)
    for true_time in self.resume_list:
        new_time += true_time
    self.song = self.song[new_time:]
    self.coming_from_loop = False
    self.testsong("sent")

执行逻辑:清除存储threading.Event()的类变量;计算歌曲剩余时长;修正歌曲索引;将当前歌曲传递给MVC架构中的controller;累加所有暂停时长并从歌曲中扣除已播放部分;设置类变量coming_from_loop(无关键影响);最后调用testsong播放音乐。

目前发现三个影响崩溃概率的因素:

  • 使用全局快捷键模块system_hotkey触发暂停时,崩溃概率远高于手动点击tkinter按钮触发暂停;未使用该模块时也曾崩溃,但错误信息不同(暂未记录)。
  • 更改歌曲已播放时长的计算逻辑后,崩溃频率显著降低:原逻辑基于播放与暂停的系统时间差,现逻辑为播放时倒计时、暂停时停止计时。
  • 仅在暂停间隔较长时间(如远超30秒)恢复时才会崩溃。

推测是线程长时间等待后执行计算(如创建Pydub.AudioSegment)时失败导致崩溃,恳请提供排查思路或解决建议。

内容的提问来源于stack exchange,提问作者NedNoodleHead

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 21:48:14