Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
Implement thread.interrupt_main
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoV committed May 4, 2011
1 parent de89b60 commit 33d5472
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Languages/IronPython/IronPython.Modules/thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ public static object start_new_thread(CodeContext/*!*/ context, object function,
return t.ManagedThreadId;
}

public static void interrupt_main() {
throw PythonOps.NotImplementedError("interrupt_main not implemented");
//throw new PythonKeyboardInterrupt();
/// <summary>
/// Stops execution of Python or other .NET code on the main thread. If the thread is
/// blocked in native code the thread will be interrupted after it returns back to Python
/// or other .NET code.
/// </summary>
public static void interrupt_main(CodeContext context) {
var thread = context.LanguageContext.MainThread;
if (thread != null) {
thread.Abort(new KeyboardInterruptException(""));
} else {
throw PythonOps.SystemError("no main thread has been registered");
}
}

public static void exit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ protected override void Initialize() {
}

PythonContext.InsertIntoPath(0, fullPath);
PythonContext.MainThread = Thread.CurrentThread;
}

protected override Scope/*!*/ CreateScope() {
Expand Down
13 changes: 13 additions & 0 deletions Languages/IronPython/IronPython/Runtime/PythonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public sealed partial class PythonContext : LanguageContext {
internal readonly List<FunctionStack> _mainThreadFunctionStack;
private CallSite<Func<CallSite, CodeContext, object, object>> _callSite0LightEh;
private List<WeakReference> _weakExtensionMethodSets;
private Thread _mainThread;

#region Generated Python Shared Call Sites Storage

Expand Down Expand Up @@ -399,6 +400,18 @@ internal TopNamespaceTracker TopNamespace {
}
}

/// <summary>
/// Gets or sets the main thread which should be interupted by thread.interrupt_main
/// </summary>
public Thread MainThread {
get {
return _mainThread;
}
set {
_mainThread = value;
}
}

public IEqualityComparer<object>/*!*/ EqualityComparer {
get { return _equalityComparer; }
}
Expand Down

0 comments on commit 33d5472

Please sign in to comment.