Closed irmen closed 5 years ago
I would recommend using __enter__
and __exit__
. That's what they are meant for. Adding an additional set of non-underscored enter
and exit
functions that called the existing functions would not add any useful functionality, but merely duplicate existing code. Such wrappers are better implemented in client-side code instead of the SoundCard API.
I can agree with that
I'm attempting to integrate soundcard as a backend library in my own sound api. This means I'm wrapping various classes in my own.
Recorder and Stream are only context managers and this is a little problematic, because that doesn't mix well with code that is using them over a longer period of time and across many scopes; I don't have a single localized place where I can use a context manager for a short time. I want to be able to keep the backend stream open all the time (until my api is closed)
I can do this by manually calling
__enter__()
and__exit__()
but it would be nice if there also is a more traditionalinit()
/close()
method pattern or something similar.edit: Actually, I managed to solve this without having to jump through some hoops, by using a loop that pulls data from elsewhere , running within the context manager, in a thread. But it still is a bit convoluted