cgt icon indicating copy to clipboard operation
cgt copied to clipboard

Dealing with exceptions (eg KeyboardInterrupt) in python functions called via C++

Open joschu opened this issue 9 years ago • 0 comments

Moving this over from the bitbucket tracker...

Suppose you run the following script CGT_FLAGS=backend=native python examples/demo_mnist.py and then hit control-C during execution. Chances are, you'll see something like the following ^CException KeyboardInterrupt in 'cycgt._pyfunc_byval' ignored ^C[1] 7414 segmentation fault CGT_FLAGS=backend=native python demo_mnist.py Some of the operations are still only implemented in python. Sometimes KeyBoardInterrupts will get caught by python and then ignored by cython, causing undesirable/unpredictable behavior. At the very least, we should abort() from cython. Better yet, we'd set some error flag, which would get caught by the C++ interpreter to stop execution, and then finally we'd raise a Python exception.

Anyway, @hojonathanho has a fix implemented that involves introducing some python exception machinery into execution.{cpp/h}. We agree that including this stuff is a bit undesirable, so we're holding off on merging for now. But I'll leave this issue as a placeholder, in case we decide to deal with it later.

joschu avatar Aug 28 '15 03:08 joschu