-
Notifications
You must be signed in to change notification settings - Fork 747
Interrupting running Python code from another thread #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
See here https://stackoverflow.com/questions/1420957/stopping-embedded-python. We currently do not expose class Interrupter
{
public Interrupter()
{
_interruptAction = DoInterrupt;
}
int DoInterrupt(IntPtr arg)
{
Exceptions.SetError(Exceptions.KeyboardInterrupt, "interrupted");
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int PendingCall(IntPtr arg);
readonly PendingCall _interruptAction;
void Interrupt()
{
IntPtr func = Marshal.GetFunctionPointerForDelegate(_interruptAction);
Runtime.Py_AddPendingCall(func, IntPtr.Zero);
}
} All |
Many thanks, i'll do that. |
Hi, unfortunately I can't get this to work. I basically used the Interrupter class you posted above, but the DoInterrupt() callback never gets invoked. Any ideas? |
Hi filmor, apologies, got it working. Had to change my C# host apps threading model. As a COM/DCOM MTA server the .exe primary thread was not the thread which eventually called Thanks again. |
Nice, I'll see whether I can prepare a PR that includes this. |
@jduncalf I think this extension should be help https://github.com/amos402/py-xtimeout |
anyone would like to submit a PR? |
I think this is not a problem that relate to pythonnet, the extension I supplied above can handle this case. |
@heartacker i have the same requirement of stopping runing code embbed in wpf. if there is any easy way to stop them. tell me thanks |
I also meet this situation. Is there any idea to stop running script which embedded in C#? |
it seems we have to wait for 3.0.0 |
Hi, does anyone know the best way to stop a currently running PyScope.Exec() call. My C# app is multi-threaded and allows users to run scripts, however where there's an infinite loop, new Python calls can be executed but I can't stop the original infinite loop.
Thanks.
The text was updated successfully, but these errors were encountered: