Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4603

Re: Aborting Python from C code

References <mailman.974.1304041735.9059.python-list@python.org> <c63e7579-16d1-4bfa-8486-8ab791343dba@glegroupsg2000goo.googlegroups.com> <BANLkTik1V3CwUY41-F0U3nxhFV=j2Bvk1g@mail.gmail.com> <BANLkTinOWxFtq-cSCk18d7HbKUYAyLCp9g@mail.gmail.com>
Date 2011-05-04 19:02 +1000
Subject Re: Aborting Python from C code
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1144.1304499763.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Apr 30, 2011 at 7:29 PM, Dylan Evans <dylan@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Aborting Python from C code Miki Tebeka <miki.tebeka@gmail.com> - 2011-04-30 01:08 -0700
  Re: Aborting Python from C code Chris Angelico <rosuav@gmail.com> - 2011-04-30 18:17 +1000
  Re: Aborting Python from C code Chris Angelico <rosuav@gmail.com> - 2011-05-04 19:02 +1000
  newbie needs help with cookielib "Sells, Fred" <fred.sells@adventistcare.org> - 2011-05-04 13:16 -0400

csiph-web