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


Groups > comp.lang.python > #9584

Re: abort python script from trace function

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '(especially': 0.07; 'currently,': 0.07; 'raises': 0.07; 'system;': 0.07; 'python': 0.08; 'scripts': 0.09; 'exception.': 0.09; 'subject:python': 0.12; 'am,': 0.13; 'received:209.85.214.174': 0.13; 'received:mail- iw0-f174.google.com': 0.13; 'wrote:': 0.15; 'egg': 0.16; 'embed': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'skip:j 20': 0.16; 'stark': 0.16; 'subject:function': 0.16; 'thread.': 0.16; '16,': 0.16; 'language': 0.20; 'ignore': 0.21; '(but': 0.22; 'archives': 0.22; 'header:In-Reply-To:1': 0.22; 'code.': 0.22; 'end,': 0.23; 'fine,': 0.23; 'interface': 0.23; 'code': 0.24; 'extent': 0.25; '(and': 0.27; 'sort': 0.28; 'objects': 0.28; 'received:209.85.214': 0.28; 'sat,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'script': 0.29; 'second': 0.29; 'do.': 0.30; 'fairly': 0.30; 'not.': 0.30; 'separate': 0.31; 'chris': 0.32; 'list': 0.32; 'done': 0.33; 'to:addr:python-list': 0.34; 'instead': 0.34; 'someone': 0.34; 'creates': 0.34; 'test': 0.34; 'that,': 0.35; 'uses': 0.35; 'file': 0.36; 'similar': 0.37; 'thread': 0.37; 'response': 0.37; 'but': 0.37; 'could': 0.37; 'received:google.com': 0.38; 'not,': 0.38; 'received:209.85': 0.38; 'user': 0.38; 'subject:: ': 0.38; 'created': 0.38; 'showing': 0.38; 'something': 0.38; 'hello,': 0.38; 'hoping': 0.38; 'run': 0.39; 'should': 0.39; 'subject:from': 0.39; 'got': 0.39; 'basic': 0.39; "there's": 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'did': 0.40; 'your': 0.60; 'back': 0.63; 'our': 0.63; 'straight': 0.66; "google's": 0.69; 'guarantee': 0.69; 'engine': 0.71; 'heavy': 0.71; 'catches': 0.84; 'perfect,': 0.84; 'timer.': 0.84; "everything's": 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ZQ+7VJNFegGdOWCH3D0psLpB5dkbus2Iw5/OZAl6enI=; b=Kn6Joah22Or9orC8RMZcrJ67lUoY7LO7+S51XGEzvQjY3GTaKZuPiaas+k9t8KtlR3 AQwdbSKoTNDsc1IVPDudhDYe0u0DOtqn5eKbWFTLhwcAHx0h9Zbe2GF7bXpfH5twTtaP aLAIQo8lZ75b5lSxcV8K6Yyz3zPTs1YGz0Ql0=
MIME-Version 1.0
In-Reply-To <C748EF7AAA82EF4C880CA9BED44A4BD62B753A82@SV950-MBX2.corp.intusurg.com>
References <C748EF7AAA82EF4C880CA9BED44A4BD62B753A82@SV950-MBX2.corp.intusurg.com>
Date Sat, 16 Jul 2011 09:47:25 +1000
Subject Re: abort python script from trace function
From Chris Angelico <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1091.1310773648.1164.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310773648 news.xs4all.nl 23851 [2001:888:2000:d::a6]:40777
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9584

Show key headers only | View raw


On Sat, Jul 16, 2011 at 8:00 AM, Dave Stark <David.Stark@intusurg.com> wrote:
> Hello,
>
> I have a multithreaded application that uses embedded python extensively.
> The main thread creates python objects that interface test equipment, and
> users execute their own python scripts that run in a separate thread.

I did something extremely similar (but without the threading), and was
majorly burnt. Poke around on the archives and you'll find the extent
to which I (and my boss) got egg on our faces; I had thought that it
would be possible to sandbox Python enough for a user to be able to
submit code. It's not. If you're fortunate, someone from this list
will create a file in /tmp, read it back, and then email you showing
how easy it was to do. If you're not, it'll be utter and complete
p0wnage.

PyErr_SetInterrupt() raises KeyboardInterrupt. It works fine, as long
as the script catches that. I had the same issues with my system; I
wanted to administratively guarantee that the script WOULD NOT take
more than X ms of CPU time. Since a Python script can catch
KeyboardInterrupt, it could ignore the watchdog timer. In the end, I
created a second watchdog that, if triggered, would longjmp straight
out past all the Python code and back to a basic cleanup-and-terminate
routine.

There's no way, currently, to make an uncatchable exception. I already
asked. The general response is (and I should have listened, instead of
muffling on and hoping that we could sandbox Python "enough to get
by") that Python is not the right language for that sort of job. I was
advised to try Javascript/ECMAScript, and Google's V8 engine is fairly
good; not perfect, but decent. Alternatively, Lua works well, but it's
a lot more effort to embed (especially if you want heavy interfacing
between the script code and your application code - everything's done
with a stack).

Chris Angelico

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


Thread

Re: abort python script from trace function Chris Angelico <rosuav@gmail.com> - 2011-07-16 09:47 +1000

csiph-web