[Python.NET] How to interrupt Python from a .NET program?

Brian Lloyd brian at zope.com
Fri Feb 6 09:56:11 EST 2004


> I have written a Python script editor in C#. It runs a script
> using PythonEngine.RunSimpleString().
>
> I need to be able to interrupt the script execution fromC#, but I
> haven't been able to figure out how to do it without crashing the process.
>
> If I try to finalize the PythonEngine, or raise a keyboard
> interrupt, either in the GUI thread, or in a Python callback
> thread (a C# delegate), I get:
>
> Fatal Python error: PyThreadState_Get: no current thread
>
> Thanks for any light anyone can shed on this.

Hmm - this probably indicates something I need to fix. In the
meantime, you can try calling PythonEngine.EnsureThread() from
the thread you are using before trying to interrupt - that should
at least make sure that Python knows about the thread. It may still
fail, but at least it should fail with a different error ;^)



Brian Lloyd        brian at zope.com
V.P. Engineering   540.361.1716
Zope Corporation   http://www.zope.com





More information about the PythonDotNet mailing list