Embedded python: how to force a break to endless looping Python script? (2)

David Bolen db3l at fitlinxx.com
Wed Aug 23 21:23:56 EDT 2000


"Warren Postma" <embed at NOSPAM.geocities.com> writes:

> The stdout redirection looks like a good candidate for starters.  Can I
> raise an exception such that
> a Python try: / except: block will not catch it? Is there a standard
> exception "so bad that we return it all the way up to C" but not so bad that
> we would automatically call exit(0) from Python?

I hope not - since to be honest I wouldn't want something that I
couldn't catch in code I wrote, although yes, it would be useful in
this specific case :-)

My expectation is that anything you'd do this way could technically be
caught by a try/except block - which is why I noted in my previous
response that this wouldn't fix a case where the script had a top
level try/except that just restarted everything.  Thus, the
alternative approach of sort of just killing off the interpreter in
the presence of a runaway script.

> The other thing I've seen is that the eval2 function checks for a global
> "things_to_do" being set to 1, then it calls a list of callbacks. I have
> thought of modifying this code slightly, to add a "thread-affinity" for the
> code, and have also thought of adding a way to raise a super-exception.

Well, if you're willing to make a change to Python itself I think you
probably have a variety of things you could do.  All you really need
is some regular check for a request for thread termination that is
outside the actual Python bytecode interpreter.  You still need to
shut down the native thread from within the thread itself to be
proper, but since the python interpreter itself is in charge of the
native thread, that shouldn't be too hard to do if the interpreter
while in that thread notices an external request for termination.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list