I am integrating a third-party C ++ package into a python application using SWIG . The package connects to the proprietary API over the network and receives updates. The general thread is that python instantiates a C ++ object, calls its functions to configure it, and then waits for updates.
I implemented a callback mechanism for updates using the functions of SWIG directors , and during testing using python or from C ++ functions called by python, this works well. Namely, I can inherit the C ++ class in Python, call its virtual functions from C ++ and see that the python code takes precedence and is executed.
Problem:
When I get updates from the network, I get:
The thread 'Win32 Thread' (0x1f78) has exited with code 0 (0x0). Unhandled exception at 0x1e0650cb in python.exe: 0xC0000005: Access violation writing location 0x0000000c.
This exception is thrown from python27.dll when the callback function is called.
My suspicion is this: I violated the GIL
AFAIU updates come from another thread and invoke python code using this thread.
At this moment I am at a loss. The SWIG director function is limited only to threads initiated in python (i.e. from python-based managed threads)?
How do I get around this? How can I induce updates from C ++ to python? Is SWIG possible?
Should I use a completely different approach?
I am open to any suggestions on this ...
source share