raise third argument question

Andrew Dalke dalke at dalkescientific.com
Sun Dec 9 03:17:17 EST 2001


Campbell:
>I don't suppose it would be possible to stick a pin in another running
>thread with the raise statement and a suitable third parameter?

I haven't seen any other answers, so under the hypothesis that
people will correct me if I'm wrong, here's my answer...

No, it isn't possible to do this.  At least not this way.

>My threads are all execfile()'ing bits of code written by people other
>than myself, and sometimes they are not too bright about using tight
>while 1: loops, and other nasties, which do not include any of the
 ...
>Please let this be possible - i have a long-running headache :)

You might do is play around with sys.settrace.  This
is often used for writing debuggers, as in
 http://www.python.org/doc/current/lib/node262.html
You might be able to use it to generate an exception in
the thread.  That is, have the callback function get the
thread id then see if it's a user function and has been
called too often / run for too long.  If so, call
thread.exit() or whatever is appropriate for your code.

Two problems with that approach might be:
  - I don't know if the callback is affected by threads or
      is even thread-safe
  - user code could still catch and ignore the exit
      exception, so at best it prevents "simple" errors.

Also, that interface is being rewritten for 2.2, and the
new code is called 'hotshot.'  Fred Drake will present it
at Python10.  There is no documentation even in the current
CVS about it (and what's in _hotshot.c isn't very helpful
to the uninitiated).

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list