Skip to content

Commit d2293a8

Browse files
author
Boxiang Sun
committed
Add thread.interrupt_main
Tk application need this method to stop main window and to some other things.
1 parent 900753b commit d2293a8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/runtime/builtin_modules/thread.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ Box* getIdent() {
198198
return boxInt(pthread_self());
199199
}
200200

201+
Box* interruptMain() {
202+
PyErr_SetInterrupt();
203+
Py_INCREF(Py_None);
204+
return Py_None;
205+
}
206+
201207
Box* stackSize() {
202208
Py_FatalError("unimplemented");
203209
}
@@ -227,6 +233,9 @@ void setupThread() {
227233
FunctionMetadata::create((void*)getIdent, BOXED_INT, 0), "get_ident"));
228234
thread_module->giveAttr("stack_size", new BoxedBuiltinFunctionOrMethod(
229235
FunctionMetadata::create((void*)stackSize, BOXED_INT, 0), "stack_size"));
236+
thread_module->giveAttr(
237+
"interrupt_main",
238+
new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)interruptMain, UNKNOWN, 0), "interrupt_main"));
230239
thread_module->giveAttr("_count", new BoxedBuiltinFunctionOrMethod(
231240
FunctionMetadata::create((void*)threadCount, BOXED_INT, 0), "_count"));
232241

0 commit comments

Comments
 (0)