pydub icon indicating copy to clipboard operation
pydub copied to clipboard

Console freezes when running a script in multithread

Open bernardohenz opened this issue 4 years ago • 4 comments

Hi, I am using pydub for converting a set of ogg files to the desired format. My script is the following:

from pydub import AudioSegment

def ogg_to_wav(ogg_file_path, wav_file_path, sample_rate=16000,channels=1):
    audio_data = AudioSegment.from_file(ogg_file_path, format='ogg')
    audio_data = AudioSegment.set_frame_rate(audio_data,sample_rate)
    audio_data = AudioSegment.set_channels(audio_data,channels)
    audio_data = AudioSegment.set_sample_width(audio_data, 2)
    duration_seconds = audio_data.duration_seconds
    if audio_data.export(wav_file_path, format='wav'):
        return True, duration_seconds
    return False, duration_seconds

When running on multithread (in my case, inside a pool.imap_unordered), my console freezes and I cannot input anything. any ideas?

bernardohenz avatar Jul 23 '20 17:07 bernardohenz

Same issue here. I run my code on Ubuntu 14.04 and libav-tools version is 6:9.20.

Mad-Devil avatar Aug 01 '20 12:08 Mad-Devil

I'm wondering if this is related to pydub's insistence on dumping a lot of crap to stdout. I'm looking for a way to make it run text-silent. Tried the logging setup and used setLevel to logging.ERROR but I'm still getting the progress bar crap. I've seen others reconnect stdout to dev null, but I don't want to disable all of the output from the entire program, I'm just looking to turn off what pydub is sending. Seems like it could hang a console as well...

kdd21 avatar Jan 28 '21 09:01 kdd21

how does your CPU and RAM use look in top/activity monitor/etc ? I suspect it's related to giving the system a lot of work, rather than the comparatively small amount of text ffmpeg outputs (small compared to the amount of data in the actual audio files)

jiaaro avatar Jan 28 '21 17:01 jiaaro

I am also experiencing this BUT the console does NOT freeze. It just does not display any input after the command is run. STDOUT is probably used to dump binary data and it "zombies out" (sorry I have no better explanation). If you try to type reset or stty echo and it should be back. ref.: https://stackoverflow.com/questions/17682934/linux-terminal-typing-feedback-gone-line-breaks-not-displayed And yes, it only happens when running multi-threaded. My guess is that this is the responsible code in the AudioSegment.from_file method:

p = subprocess.Popen(conversion_command, stdin=stdin_parameter,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Now the question is how can this be fixed?

adamjakab avatar May 04 '24 21:05 adamjakab