Aborting Python from C code

Chris Angelico rosuav at gmail.com
Wed May 4 05:02:40 EDT 2011


On Sat, Apr 30, 2011 at 7:29 PM, Dylan Evans <dylan at contentfree.info> wrote:
> I think i see what you are trying to do but it depends on the environment
> and your goals.
> Generally i think you need to separate your code by forking (or perhaps you
> have already done that?),
> then you can run a check to see if the process died as expected. I don't
> know though, this not much
> information to go on, but if you are running untrusted code then you need to
> be able to isolate and kill it.

Well, I've gone with a slight variant on this. If the Python script
doesn't terminate in a timely manner, the process will be killed with
a longjmp straight from the signal handler (the setjmp having been
done long long ago back when the process initialized itself). So
Py_Finalize() will be called, but no other Python-related functions
_at all_, and the process promptly terminates. I'm assuming that
Python will flush out all its state on process termination (that is,
it doesn't hang onto any system-global resources).

Thanks for the advice!

Chris Angelico



More information about the Python-list mailing list