Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed6.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.04; 'handler': 0.05; 'currently,': 0.07; 'python?': 0.07; 'raises': 0.07; 'python': 0.07; 'abort': 0.16; 'appreciated!': 0.16; 'bypassed': 0.16; 'except:': 0.16; 'return.': 0.16; 'this?': 0.18; 'part,': 0.19; 'received:209.85.214.174': 0.23; 'received:mail- iw0-f174.google.com': 0.23; 'subject:code': 0.23; 'script': 0.26; "i'm": 0.26; 'chris': 0.27; 'pass': 0.27; 'message- id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'seem': 0.30; 'to:addr :python-list': 0.32; 'another': 0.32; 'thinking': 0.33; 'that,': 0.35; 'like:': 0.35; 'trigger': 0.35; 'try:': 0.35; 'rather': 0.36; 'received:209.85': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'help': 0.39; 'received:209.85.214': 0.39; 'signal': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'works': 0.40; 'would': 0.40; 'header:Received:5': 0.40; 'order': 0.61; 'our': 0.63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=/tWhEj1QZgDkLiJQ5QsRat20MhA2Obtn5tPA3AhUyPY=; b=U7JvQSjR9RvAhsQWUIEjdQVfR2m4VlrV2/VXQosZ1BqWu3p0tnPElwgo7eI/ZnHkhv iZ7P5Otx8ROEJ6ECcN2Cn0wMqhyHZlfekHEOhGB+tdr2pBnL/EOTc6S8DcdeB0TONE7e kK6N6YhkRVLyZt9jUhA+KpvhfgKSbIp00SB1Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=xT55fCSAf3HQ5yDNN9GrwKTlqjwRLJdYop0/0GNoVK4F7krfco7f88oYHjXPNwHGLj eEVIMLldByaMHb2ODCl8usri3Nte5EiSxhdfjf+0fS1UuzIg+O8+Lmpa3qeSoxxFinnM agsTv8oTH30oJM7pXQT5AtJg0P5eajDDP1X5M= MIME-Version: 1.0 Date: Fri, 29 Apr 2011 11:48:52 +1000 Subject: Aborting Python from C code From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 22 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304041736 news.xs4all.nl 81483 [::ffff:82.94.164.166]:54423 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4285 In our sandboxed Python environment, I would like to be able to trigger an abort of the currently-running Python script (from a signal handler or another thread). Currently, I use PyErr_SetInterrupt() which raises KeyboardInterrupt in the script; this works for the most part, but can be bypassed with a script like: while True: try: while True: pass except: pass I want to be able to administratively order Python to stop executing. Is it possible to make KeyboardInterrupt non-catchable from Python? Alternatively, can I use Py_AddPendingCall to do this? I'd rather not use setjmp/longjmp if I can help it, as they seem a tad brutal, but I'm thinking in terms of a call that, in effect, doesn't return. Any ideas would be appreciated! Chris Angelico