Do you have some logs at hand for these deadlocks?
As most of the exception handling and all of the keypress handling takes part in Python, I am quite optimistic that this can be tracked down and possibly mitigated without the core code.
But even if the error is finallly in C++, you could at least use the Python parts for further debugging (i.e. adding print commands etc.).