From 8abf06bedf055b438f8fd66dff4e8b58107886a8 Mon Sep 17 00:00:00 2001 From: Danny Date: Mon, 2 Dec 2019 21:39:44 +0000 Subject: [PATCH] Prevent hang on close after capturing audio Currently, after recording audio using pyalsaaudio, the client is unable to close the device. The reason is that PulseAudio client tries to drain the pipe to the PulseAudio server (presumably in order to prevent Broken Pipe error) on closing. That will never finish since new data will always arrive in the pipe. Worse, the __del__ handler was auto-closing and thus auto-hanging. Therefore, pause before de-allocating. --- alsaaudio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/alsaaudio.c b/alsaaudio.c index 624a808..2566097 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -440,6 +440,7 @@ alsapcm_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static void alsapcm_dealloc(alsapcm_t *self) { if (self->handle) { + snd_pcm_pause(self->handle, 1); snd_pcm_drain(self->handle); snd_pcm_close(self->handle); }