Is there a way to interrupt Python?

Michael Hudson mwh21 at
Fri Mar 17 15:30:40 CET 2000

Alex Farber <farber at> writes:

> Hi, 
> Michael Hudson wrote:
> > Alex Farber <farber at> writes:
> > > is there a way to interrupt Python when it is executing
> > > PyEval_EValCode() or PyRun_*() in an embedding application?
> > >
> > > I would like to be able to stop it by pressing CTRL-C. Maybe
> > > there is a flag or some thread ref. which I could kill somehow?
> > 
> > Getting a SIGINT sent to the process *should* work, ie. pressing
> > ctrl-C should work.
> thanks for your reply. Yes, CTRL-C works - my program exits.
> The problem is that it is the same process. So I am looking
> for a way to interrupt PyEval_EValCode() or PyRun_*()

Catch KeyboardInterrupt exceptions then.  Does Python install it's
usual signal handlers when it's embedded inside another app?  Can it
be made to?

I can't see how you're going to do this w/o signals, so you might as
well use SIGINT.

Hmm, you might want to look at PyOS_InitInterrupts ...


very few people approach me in real life and insist on proving they are
drooling idiots.                         -- Erik Naggum, comp.lang.lisp

More information about the Python-list mailing list