How to wrap a message loop with callbacks using boost :: python (given the GIL)

I want to wrap an existing C ++ library that includes a blocking message loop and call handler functions for Python using boost :: python . For example:.

import my_boostpython_lib

def my_handler_fn():
    do_something()

md = my_boostpython_lib.message_dispatcher()

# calls a C++ object method and blocks
md.run_message_loop(my_handler_fn)

      

Calling a Python function from C ++ is not a problem, but the message loop should free GIL

, as otherwise it blocks the entire Python interpreter (see here , here and the associated additional ticket )

As stated here , it is important to block again GIL

before calling the Python function.

Basically this seems clear to me, but I'm wondering if there are some elegant solutions out there that show how this can be done. For example. it would be really nice if I only had to modify the boost :: python wrapper (instead of changing the library I want to wrap)

Do you know of any working example that includes boost :: python , callbacks using an object-oriented approach (and possibly blocking functions that release GIL

) where I can copy some best practices from?

+3


source to share





All Articles