Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(33)

Unified Diff: src/org/python/modules/thread/thread.java

Issue 2810: SystemRestart exception to restart the interpreter (Closed) SVN Base: https://jython.svn.sourceforge.net/svnroot/jython/branches/asm
Patch Set: Created 1 year, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: src/org/python/modules/thread/thread.java
===================================================================
--- src/org/python/modules/thread/thread.java (revisión: 5073)
+++ src/org/python/modules/thread/thread.java (copia de trabajo)
@@ -8,13 +8,16 @@
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.core.PyString;
+import org.python.core.PyTableCode;
import org.python.core.PyType;
import org.python.core.PyTuple;
public class thread implements ClassDictInit {
private static volatile long stack_size = 0; // XXX - can we figure out the current stack size?
+ private static ThreadGroup group = new ThreadGroup("jython-threads");
+
public static PyString __doc__ = new PyString(
"This module provides primitive operations to write multi-threaded "+
"programs.\n" +
@@ -24,12 +27,13 @@
public static void classDictInit(PyObject dict) {
dict.__setitem__("LockType", PyType.fromClass(PyLock.class));
dict.__setitem__("_local", PyLocal.TYPE);
+ dict.__setitem__("interruptAllThreads", null);
}
public static PyObject error = new PyString("thread.error");
public static void start_new_thread(PyObject func, PyTuple args) {
- Thread pt = new FunctionThread(func, args.getArray(), stack_size);
+ Thread pt = new FunctionThread(func, args.getArray(), stack_size, group);
PyObject currentThread = func.__findattr__("im_self");
if (currentThread != null) {
PyObject isDaemon = currentThread.__findattr__("isDaemon");
@@ -46,6 +50,23 @@
pt.start();
}
+ /**
+ * Interrupts all running threads spawned by the thread module.
+ *
+ * This works in conjuntion with:<ul>
+ * <li>{@link PyTableCode#call(org.python.core.PyFrame, PyObject)}:
+ * checks for the interrupted status of the current thread and raise
+ * a SystemRestart exception if a interruption is detected.</li>
+ * <li>{@link FunctionThread#run()}: exits the current thread when a
+ * SystemRestart exception is not caught.</li>
+ *
+ * Thus, it is possible that this doesn't make all running threads to stop,
+ * if SystemRestart exception is caught.
+ */
+ public static void interruptAllThreads() {
+ group.interrupt();
+ }
+
public static PyLock allocate_lock() {
return new PyLock();
}
@@ -81,4 +102,4 @@
throw Py.TypeError("stack_size() takes at most 1 argument (" + args.length + "given)");
}
}
-}
+}

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497