I'm trying to develop a C-based application which embeds one or more Python interpreters. I'm using gtk-things in the C-parts, and logically calling gtk_main() within that.
The Python interpreters are created in separate pthreads using Py_NewInterpreter(), and basically running forever (a 'while True' loop is added to the end in case the script terminates).
Now I'd like to use pyGTK in those scripts, which seems to work until there's a callback (signal emitted). You can register signal handlers to point to parts in the Python scripts ok, but it seems that the gtk main loop can't direct them correctly when they happen, causing segfaults like the log below.
I'm guessing it might have something to do with the python thread state not being initialized correctly, but not sure. Would anyone have insight on what I'm doing wrong or what to check?

#0  0xb7ecfc9a in PyFrame_New () from /usr/lib/libpython2.5.so.1.0
#1  0xb7f376ed in PyEval_EvalCodeEx () from /usr/lib/libpython2.5.so.1.0
#2  0xb7ed09b6 in ?? () from /usr/lib/libpython2.5.so.1.0
#3  0xb7eae327 in PyObject_Call () from /usr/lib/libpython2.5.so.1.0
#4  0xb7f30f7c in PyEval_CallObjectWithKeywords () from /usr/lib/libpython2.5.so.1.0
#5  0xb7eaeb5c in PyObject_CallObject () from /usr/lib/libpython2.5.so.1.0
#6  0xb424face in ?? () from /usr/lib/pymodules/python2.5/gtk-2.0/gobject/_gobject.so
#7  0xb76e113a in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#8  0xb76f761d in ?? () from /usr/lib/libgobject-2.0.so.0
#9  0xb76f8bfc in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#10 0xb76f9076 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#11 0xb7ab3a8a in gtk_button_clicked () from /usr/lib/libgtk-x11-2.0.so.0
#12 0xb7ab5048 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#13 0xb76eecac in g_cclosure_marshal_VOID__VOID () from /usr/lib/libgobject-2.0.so.0
#14 0xb76df7a9 in ?? () from /usr/lib/libgobject-2.0.so.0
#15 0xb76e113a in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#16 0xb76f6eba in ?? () from /usr/lib/libgobject-2.0.so.0
#17 0xb76f8bfc in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#18 0xb76f9076 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#19 0xb7ab3b2a in gtk_button_released () from /usr/lib/libgtk-x11-2.0.so.0
#20 0xb7ab3b73 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#21 0xb7b70e74 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#22 0xb76df7a9 in ?? () from /usr/lib/libgobject-2.0.so.0
#23 0xb76e113a in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#24 0xb76f7266 in ?? () from /usr/lib/libgobject-2.0.so.0
#25 0xb76f8a7b in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#26 0xb76f9076 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#27 0xb7c9d156 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#28 0xb7b694cd in gtk_propagate_event () from /usr/lib/libgtk-x11-2.0.so.0
#29 0xb7b6a857 in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
#30 0xb79f3dda in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#31 0xb7636305 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#32 0xb7639fe8 in ?? () from /lib/libglib-2.0.so.0
#33 0xb763a527 in g_main_loop_run () from /lib/libglib-2.0.so.0
#34 0xb7b6ae19 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
This is a situation where you are better off making one more Python interpreter and doing all your GTK work by sending Python snippets to that special GTK helper interpreter. That way your C code never uses GTK directly and you only need to worry about coordinating between the Python threads.
pygtk and native gtk_main(); mixing