How does the Python GTK binding work without freezing the CPython eval loop?

Viewed 36

As you know, the way GTK works is that when you call the basic g_application_run function, the library takes total control of the thread - it enters and endless event loop, and anything else that happens in the program must be invoked by said event loop.

If so, I would like to understand how the CPython binding for GTK works.

CPython's execution of code is based on an internal bytecode interpretation loop. However, as we know by calling g_application_run one surrenders all control of the thread to the infinite GTK event loop. Thus - the Python interpreter loop should freeze. This seems to be a problem, because it seems to me no further Python code should be able to execute in this situation.

However, of course in Python GTK applications, Python code is allowed to execute after GTK has been started. For example, in response to events such as button clicks.

So how is this issue resolved in the GTK Python binding implementation?

Please note that I am asking this technical question, after opening a broader architectural question on SE.SE and receiving a suggestion to look at the Python binding implementation. I have not been able to sufficiently understand the source code after having tried for a while, and this is why I'm seeking answers here from those who are familiar with it.

0 Answers
Related