I'm curious on how would one accomplish event driven programming from a language like python (or other, but for simplicity sake, python will do.). By that I mean providing a system that allow programmer to hook functions to certain events, and fire those events when triggered. (Basically the APIs behind all the GUI toolkits that connects events to functions, and how they recognize events in a main loop).
What I'm thinking right now is a while loop in python in a separate thread that will pick up events as they are triggered (checking conditions). However that seems inefficient.
Any thoughts/example code?