summaryrefslogtreecommitdiff
path: root/src/buildstream/_scheduler/jobs/_job.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildstream/_scheduler/jobs/_job.pyx')
-rw-r--r--src/buildstream/_scheduler/jobs/_job.pyx15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/buildstream/_scheduler/jobs/_job.pyx b/src/buildstream/_scheduler/jobs/_job.pyx
new file mode 100644
index 000000000..82f6ab044
--- /dev/null
+++ b/src/buildstream/_scheduler/jobs/_job.pyx
@@ -0,0 +1,15 @@
+from cpython.pystate cimport PyThreadState_SetAsyncExc
+from cpython.ref cimport PyObject
+from ..._signals import TerminateException
+
+
+# terminate_thread()
+#
+# Ask a given a given thread to terminate by raising an exception in it.
+#
+# Args:
+# thread_id (int): the thread id in which to throw the exception
+#
+def terminate_thread(long thread_id):
+ res = PyThreadState_SetAsyncExc(thread_id, <PyObject*> TerminateException)
+ assert res == 1