Reputation: 21
I'm working on a script to help me grade student homework assignments. They may contain long-running turtle tasks in addition to other code. I want to run that code inside a local scope where I can override various turtle functions to make the code easier to grade. When I tried to do so, I encountered unexpected errors.
I want to process the turtle tasks and run my unit test suite. I created the following small example minimum_reproducible_example to showcase my issue.
#mre.py
import turtle
import threading
def run_turtle_code():
t = turtle.Turtle()
for _ in range(4):
t.forward(100)
t.right(90)
turtle.done()
def run_turtle_in_thread():
thread = threading.Thread(target=run_turtle_code)
thread.start()
thread.join()
if __name__ == "__main__":
run_turtle_in_thread()
When I try to run the above code example in any of the latest released Python versions for 3.6-3.10, I get the same error:
2023-09-26 11:42:25.542 python[6422:91998] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00007ff80cc8018a __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80c7a642b objc_exception_throw + 48
2 CoreFoundation 0x00007ff80cca82f6 -[NSException raise] + 9
3 AppKit 0x00007ff80fcc9e7e -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 307
4 AppKit 0x00007ff80fcb6394 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1227
5 AppKit 0x00007ff80fcb5ec2 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
6 libtk8.6.dylib 0x00000001075078f8 TkMacOSXMakeRealWindowExist + 692
7 libtk8.6.dylib 0x0000000107507519 TkWmMapWindow + 63
8 libtk8.6.dylib 0x0000000107474cc3 MapFrame + 59
9 libtcl8.6.dylib 0x0000000107250520 TclServiceIdle + 75
10 libtcl8.6.dylib 0x0000000107234c20 Tcl_DoOneEvent + 341
11 libtk8.6.dylib 0x00000001074f96da TkpInit + 762
12 libtk8.6.dylib 0x000000010746d59c Initialize + 2402
13 _tkinter.cpython-38-darwin.so 0x0000000106c17ce4 Tcl_AppInit + 84
14 _tkinter.cpython-38-darwin.so 0x0000000106c125ba Tkapp_New + 602
15 _tkinter.cpython-38-darwin.so 0x0000000106c11ee1 _tkinter_create + 561
16 libpython3.8.dylib 0x0000000106cf2de2 cfunction_vectorcall_FASTCALL + 178
17 libpython3.8.dylib 0x0000000106d96ef4 call_function + 356
18 libpython3.8.dylib 0x0000000106d93bc9 _PyEval_EvalFrameDefault + 28105
19 libpython3.8.dylib 0x0000000106d97f34 _PyEval_EvalCodeWithName + 3204
20 libpython3.8.dylib 0x0000000106cb28fc _PyFunction_Vectorcall + 236
21 libpython3.8.dylib 0x0000000106d96ef4 call_function + 356
22 libpython3.8.dylib 0x0000000106d93bc9 _PyEval_EvalFrameDefault + 28105
23 libpython3.8.dylib 0x0000000106cb278b function_code_fastcall + 171
24 libpython3.8.dylib 0x0000000106cb1c8c _PyObject_FastCallDict + 220
25 libpython3.8.dylib 0x0000000106cb3343 _PyObject_Call_Prepend + 131
26 libpython3.8.dylib 0x0000000106d0eb58 slot_tp_init + 184
27 libpython3.8.dylib 0x0000000106d09c94 type_call + 292
28 libpython3.8.dylib 0x0000000106cb1e59 _PyObject_MakeTpCall + 377
29 libpython3.8.dylib 0x0000000106d97020 call_function + 656
30 libpython3.8.dylib 0x0000000106d93c6a _PyEval_EvalFrameDefault + 28266
31 libpython3.8.dylib 0x0000000106cb278b function_code_fastcall + 171
32 libpython3.8.dylib 0x0000000106cb1c8c _PyObject_FastCallDict + 220
33 libpython3.8.dylib 0x0000000106cb3343 _PyObject_Call_Prepend + 131
34 libpython3.8.dylib 0x0000000106d0eb58 slot_tp_init + 184
35 libpython3.8.dylib 0x0000000106d09c94 type_call + 292
36 libpython3.8.dylib 0x0000000106cb1e59 _PyObject_MakeTpCall + 377
37 libpython3.8.dylib 0x0000000106d97020 call_function + 656
38 libpython3.8.dylib 0x0000000106d93c6a _PyEval_EvalFrameDefault + 28266
39 libpython3.8.dylib 0x0000000106cb278b function_code_fastcall + 171
40 libpython3.8.dylib 0x0000000106d96ef4 call_function + 356
41 libpython3.8.dylib 0x0000000106d93c6a _PyEval_EvalFrameDefault + 28266
42 libpython3.8.dylib 0x0000000106d97f34 _PyEval_EvalCodeWithName + 3204
43 libpython3.8.dylib 0x0000000106cb28fc _PyFunction_Vectorcall + 236
44 libpython3.8.dylib 0x0000000106cb1c8c _PyObject_FastCallDict + 220
45 libpython3.8.dylib 0x0000000106cb3343 _PyObject_Call_Prepend + 131
46 libpython3.8.dylib 0x0000000106d0eb58 slot_tp_init + 184
47 libpython3.8.dylib 0x0000000106d09c94 type_call + 292
48 libpython3.8.dylib 0x0000000106cb1e59 _PyObject_MakeTpCall + 377
49 libpython3.8.dylib 0x0000000106d97020 call_function + 656
50 libpython3.8.dylib 0x0000000106d93bc9 _PyEval_EvalFrameDefault + 28105
51 libpython3.8.dylib 0x0000000106cb278b function_code_fastcall + 171
52 libpython3.8.dylib 0x0000000106cb2174 PyVectorcall_Call + 100
53 libpython3.8.dylib 0x0000000106d93ed3 _PyEval_EvalFrameDefault + 28883
54 libpython3.8.dylib 0x0000000106cb278b function_code_fastcall + 171
55 libpython3.8.dylib 0x0000000106d96ef4 call_function + 356
56 libpython3.8.dylib 0x0000000106d93ba5 _PyEval_EvalFrameDefault + 28069
57 libpython3.8.dylib 0x0000000106cb278b function_code_fastcall + 171
58 libpython3.8.dylib 0x0000000106d96ef4 call_function + 356
59 libpython3.8.dylib 0x0000000106d93ba5 _PyEval_EvalFrameDefault + 28069
60 libpython3.8.dylib 0x0000000106cb278b function_code_fastcall + 171
61 libpython3.8.dylib 0x0000000106cb51c3 method_vectorcall + 323
62 libpython3.8.dylib 0x0000000106cb2174 PyVectorcall_Call + 100
63 libpython3.8.dylib 0x0000000106e3926b t_bootstrap + 75
64 libpython3.8.dylib 0x0000000106de9ff9 pythread_wrapper + 25
65 libsystem_pthread.dylib 0x00007ff80cb2d1d3 _pthread_start + 125
66 libsystem_pthread.dylib 0x00007ff80cb28bd3 thread_start + 15
)
libc++abi: terminating due to uncaught exception of type NSException
I'm running Mac OS: 13.5.1 Any help would be appreciated. I don't see this as a multi-threading issue, but I didn't see a tag for the built-in python threading module.
Upvotes: 0
Views: 49