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

Warren Postma embed at NOSPAM.geocities.com
Wed Aug 23 13:08:00 EDT 2000


> While I haven't tried this yet myself, presumably you are getting
> control within your C code whenever the embedded script calls any
> functions you export, or at a minimum whenever any output is generated
> since stdout is redirected to your functions, at that point you have C
> code executing within the right context of the script's Python thread.
>
> What happens if you just have a flag that your stdout redirection (or
> some other regularly called function) checks, and if the script is
> supposed to be terminated, that function generates an exception.  That
> should then generate the exception to the script itself from within
> the problem thread.

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?

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.

Hmm.

Warren





More information about the Python-list mailing list