Avoid returning in finally

Specifically reraise KeyboardInterrupt, SystemExit
Swallow other BaseExceptions due to the way the standard library uses
them and the intent of this function
This commit is contained in:
Michael H 2024-10-30 08:08:45 -04:00 committed by GitHub
parent ed615887f0
commit d08fd59434
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -588,22 +588,26 @@ class FFmpegOpusAudio(FFmpegAudio):
loop = asyncio.get_running_loop()
try:
codec, bitrate = await loop.run_in_executor(None, lambda: probefunc(source, executable))
except Exception:
except (KeyboardInterrupt, SystemExit):
raise
except BaseException:
if not fallback:
_log.exception("Probe '%s' using '%s' failed", method, executable)
return # type: ignore
return None, None
_log.exception("Probe '%s' using '%s' failed, trying fallback", method, executable)
try:
codec, bitrate = await loop.run_in_executor(None, lambda: fallback(source, executable))
except Exception:
except (KeyboardInterrupt, SystemExit):
raise
except BaseException:
_log.exception("Fallback probe using '%s' failed", executable)
else:
_log.debug("Fallback probe found codec=%s, bitrate=%s", codec, bitrate)
else:
_log.debug("Probe found codec=%s, bitrate=%s", codec, bitrate)
finally:
return codec, bitrate
return codec, bitrate
@staticmethod
def _probe_codec_native(source, executable: str = 'ffmpeg') -> Tuple[Optional[str], Optional[int]]: