Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.04; 'handler': 0.05; 'onto': 0.05; 'variant': 0.07; 'python': 0.07; 'flush': 0.09; 'initialized': 0.09; 'terminate': 0.09; 'pm,': 0.11; 'wrote:': 0.14; 'called,': 0.16; 'expected.': 0.16; 'forking': 0.16; 'goals.': 0.16; 'itself).': 0.16; 'terminates.': 0.16; 'termination': 0.16; 'timely': 0.20; '(or': 0.22; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'trying': 0.23; 'received:209.85.214.174': 0.23; 'received:mail- iw0-f174.google.com': 0.23; 'subject:code': 0.23; 'script': 0.26; 'ago': 0.26; 'environment': 0.26; "i'm": 0.26; 'chris': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'thanks': 0.29; 'depends': 0.29; 'sat,': 0.29; 'assuming': 0.29; '(the': 0.30; 'this.': 0.30; 'it.': 0.31; 'perhaps': 0.32; 'to:addr :python-list': 0.32; 'done': 0.32; "i've": 0.33; 'generally': 0.33; 'on,': 0.33; 'running': 0.36; 'think': 0.36; 'received:209.85': 0.37; 'run': 0.37; 'apr': 0.38; 'dylan': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'received:209.85.214': 0.39; 'signal': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'header:Received:5': 0.40; 'straight': 0.60; 'back': 0.61; '2011': 0.62; 'gone': 0.77; '30,': 0.80; 'isolate': 0.84; 'evans': 0.91; 'killed': 0.91; 'promptly': 0.93; 'died': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=UNsJ9ItN0T79z3BHvbiJTSci5pHfMStN2hEh6sc6Yag=; b=N0g4ju0qYnnPgniRRNaUrdllMFQf1QtIT+PpWEZn6fk+bwfROdX4ZO6tSClYg/d4l0 QXc3FopqMWfBa1dA+ggAqD80AaI2KxKNBfr9MitIFgHyVJ341+K1m0ScAjWa+eGumPFi GTYh5ADqJUu7ennswNEXE0X2hJ+ka99s94LSs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=EuyB25NbNWP4zOrZzVrNK4IaOL7Ev3yXmLXWu0+OUe9nunz2lLNXLaMW6hv9OACAoY SGqu7ycFVLAeJY2Z86AQxLjGj6cdt0EKLAzqfbpjZfNqTaLndmlBcVgADrxr4LPFYuuk GOapmoOqirmVcrDtInVoj2R8K+0HIp/DXu34w= MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 4 May 2011 19:02:40 +1000 Subject: Re: Aborting Python from C code From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304499764 news.xs4all.nl 81474 [::ffff:82.94.164.166]:50547 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4603 On Sat, Apr 30, 2011 at 7:29 PM, Dylan Evans 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=A0separate=A0your code by forking (or perha= ps 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