Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass/catch/respond to Python's KeyboardInterrupt in C++?

I have a simple library written in C++ which I'm creating a Python wrapper for using boost.python. Some functions take a long time to execute (over 30 seconds), and I would like to make it interruptible so that when I hit ctrl-d to trigger KeyboardInterrupt in the python interpreter, I'm somehow able to respond to that in C++.

Is there a way to do this? I couldn't find any information about interrupts and boost.python at boost.org or python.org.

like image 504
Magnus W Avatar asked Oct 20 '10 03:10

Magnus W


1 Answers

Call PyErr_CheckSignals() every so often.

like image 154
Ignacio Vazquez-Abrams Avatar answered Sep 18 '22 09:09

Ignacio Vazquez-Abrams