-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathFunctionThread.java
More file actions
43 lines (38 loc) · 1.34 KB
/
FunctionThread.java
File metadata and controls
43 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.python.core;
import java.util.concurrent.atomic.AtomicInteger;
public class FunctionThread extends Thread
{
private final PyObject func;
private final PyObject[] args;
private final PySystemState systemState;
private static AtomicInteger counter = new AtomicInteger();
public FunctionThread(PyObject func, PyObject[] args, long stack_size, ThreadGroup group) {
super(group, null, "Thread", stack_size);
this.func = func;
this.args = args;
this.systemState = Py.getSystemState();
this.setName("Thread-"+Integer.toString(counter.incrementAndGet()));
}
public void run() {
Py.setSystemState(systemState);
try {
func.__call__(args);
} catch (PyException exc) {
if (exc.match(Py.SystemExit)) {
return;
}
Py.stderr.println("Unhandled exception in thread started by " + func);
Py.printException(exc);
}
}
@Override
public String toString() {
ThreadGroup group = getThreadGroup();
if (group != null) {
return String.format("FunctionThread[%s,%s,%s]", getName(), getPriority(),
group.getName());
} else {
return String.format("FunctionThread[%s,%s]", getName(), getPriority());
}
}
}