fourMs / MGT-python

Musical Gestures Toolbox for Python
https://www.uio.no/ritmo/english/research/labs/fourms/downloads/software/musicalgesturestoolbox/mgt-python/index.html
GNU General Public License v3.0
52 stars 11 forks source link

Audio functions hang outside of notebook #191

Closed balintlaczko closed 3 years ago

balintlaczko commented 3 years ago

While investigating #190, found this. On Windows, everything works as expected - both in the notebook, and in the terminal (via IPython or script call), on Ubuntu everything works as expected in the notebook. However, in the Terminal (using IPython or via script call) any audio function will cause the Terminal to hang forever (without any CPU use) which is quite odd.

balintlaczko commented 3 years ago

It seems to be some kind of conflict between librosa and matplotlib. (More details soon.)

balintlaczko commented 3 years ago

Minimal code to reproduce:

import matplotlib.pyplot as plt
import librosa

y, sr = librosa.load('dance.avi', sr=None)
print('Loaded file.')

fig, ax = plt.subplots(figsize=(12, 6), dpi=300)
print('Made plots.')

The progam will print 'Loaded file.' and then it halts forever (even KeyboardInterrupt won't work). If I am doing either the librosa.load or the plt.subplots everything is fine. If I do plt.subplots and after that librosa.load it will also work. But if I first load the file and then make the subplots (like above) I get into the deadlock.

balintlaczko commented 3 years ago

Found reference: https://stackoverflow.com/questions/46806318/librosa-stops-matplotlib-from-working

balintlaczko commented 3 years ago

Somewhat intuitively found a fix, which also seem to solve #190 at the same time. It is the opposite of clever, but it works. In audio.py after all imports:

plt.plot()
plt.close()

This somehow fixes everything. Tested in notebook/terminal on windows/ubuntu.