I'm writing a small python library in C++ as a project, using MiniAudio to make a synthesizer, and Pybind11 with CMake to build a .pyd.

I've managed to avoid making my library into a big class, but this means no constructor and destructor. With the audio library, I want to initialise devices, channels etc at import- which I have done by adding my initialisation function to my PYBIND11_MODULE function. However, I'm not sure how to get a function to run on exit too. As much as this is probably fine, as my uninit() function just does memory cleanup, it feels like bad practice to leave calling this to the user, as I'm sure there's little reason for the user to run it if they're just about to close Python.

I wondered if there's any clever workarounds for this that don't require me to pack the whole thing in a class (for security and speed reasons). I'm trying to keep it smooth as possible at runtime to work well on mid-/low-range hardware

Kate Goss's user avatar

4

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.