【问题标题】:Matplotlib hangs if AVAssetReader was used如果使用 AVAssetReader,则 Matplotlib 挂起
【发布时间】:2014-12-19 18:05:02
【问题描述】:

我有一个对音频文件执行一些操作的库。出于测试目的,我制作了一个 python 接口(使用 boost::python),现在尝试可视化一些数据。

当我尝试制作一些 matplotlib 绘图时,我遇到了以下问题:如果我使用库读取媒体文件,然后调用 matplotlib.pyplot.show() matplotlib UI 在它出现后立即挂起:我看到绘图但无法关闭/调整大小/交互随着窗口,鼠标光标显示“忙轮”。

我找到了导致此冻结的行(如果我将 return 放在 show() 之前的行可以正常工作并且如果 retrun 在下一行 show() 挂起):

mReader  = [[AVAssetReader alloc]initWithAsset:ass error:&mReaderError];

那么发生了什么:

  • 调用了本机函数
  • GIL 已发布 (PyEval_SaveThread)
  • [[AVAssetReader alloc]initWithAsset] 被调用
  • 重新获得 GIL (PyEval_RestoreThread)
  • 本机函数返回
  • plt.plot([1])
  • plt.show()

matplotlib 挂起。 我很确定库代码本身很好(它已经过测试并且在 osx 和 ios 上运行良好)但是使用 CoreAudio 和“GUI 中的东西”之间存在一些冲突。

这是挂起进程的部分回溯:

frame #0: 0x00007fff8b778ef8 CoreFoundation`CFRunLoopRunSpecific + 440
frame #1: 0x00007fff8d7287b7 HIToolbox`ReceiveNextEventCommon + 479
frame #2: 0x00007fff8d7285bc HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 65
frame #3: 0x00007fff8e48524e AppKit`_DPSNextEvent + 1434
frame #4: 0x00007fff8e48489b AppKit`-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
frame #5: 0x00007fff8e47899c AppKit`-[NSApplication run] + 553
frame #6: 0x00000001054b3fea _macosx.so`show + 218
frame #7: 0x00000001000997cc Python`PyEval_EvalFrameEx + 17823
frame #8: 0x000000010009d103 Python`fast_function + 203

有什么想法吗?

【问题讨论】:

    标签: python c++ macos matplotlib core-audio


    【解决方案1】:

    这实际上不是答案,而是一种解决方法。它使事情变得可行,但太丑陋而无法成为最终解决方案。

    如果使用 UI 之前 AVAssetReader 一切正常。我认为在这种情况下某些东西正在正确初始化。

    这段代码挂了:

    data = native_module.get_data_using_coreaudio()
    plt.plot(data)
    plt.show()
    

    但事实并非如此:

    plt.plot([0])
    plt.show()
    plt.cla()
    data = native_module.get_data_using_coreaudio()
    plt.plot(data)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 2011-01-15
      相关资源
      最近更新 更多