tags:

views:

99

answers:

2

How can I ensure a python program can be interrupted via Ctrl-C, or a similar mechanism, when it is deadlocked in code within a DLL?

+1  A: 

Not sure if this is exactly what you are asking, but there are issues when trying to interrupt (via Ctrl-C) a multi-threaded python process. Here is a video of a talk about the python Global Interpreter Lock that also discusses that issue:

Mindblowing Python GIL

Karl Voigtland
A: 

You might want to take a look at this mailing list for a couple other suggestions, but there aren't any conclusive answers.

I've encountered the issue several times, and I can at least confirm that this happens when using FFI in Haskell. I could have sworn that I once saw something in Haskell's FFI documentation mentioning that DLLs would not return from a ctrl-c signal, but I'm not having any luck finding that document.

You can try using ctrl-break, but that's not working to break out of a DLL in Haskell and I'm doubting it will work in Python either.


Update: ctrl-break does work for me in Python when ctrl-c does not, during a call to a DLL function in an infinite loop.

Mark Rushakoff