Harden recorder shutdown with guaranteed stream close
This commit is contained in:
parent
48d7460f57
commit
8b3532f2ca
2 changed files with 94 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from dataclasses import dataclass, field
|
||||
import logging
|
||||
from typing import Any, Iterable
|
||||
|
||||
import numpy as np
|
||||
|
|
@ -70,8 +71,19 @@ def start_recording(input_spec: str | int | None) -> tuple[Any, RecordResult]:
|
|||
|
||||
def stop_recording(stream: Any, record: RecordResult) -> np.ndarray:
|
||||
if stream:
|
||||
stream.stop()
|
||||
stream.close()
|
||||
stop_error = None
|
||||
try:
|
||||
stream.stop()
|
||||
except Exception as exc:
|
||||
stop_error = exc
|
||||
try:
|
||||
stream.close()
|
||||
except Exception as close_exc:
|
||||
if stop_error is None:
|
||||
raise
|
||||
logging.warning("stream close failed after stop failure: %s", close_exc)
|
||||
if stop_error is not None:
|
||||
raise stop_error
|
||||
return _flatten_frames(record.frames)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue