Recently, I\'ve been diving into the Twisted docs. From what I gathered, the basis of Twisted\'s functionality is the result of it\'s event loop called the \"Reactor\". The
I will try to elaborate:
The program yields control and go to sleep on wait for events. I suppose the most interesting part here is event. Event is: on external demand (receiving network packet, click on a keyboard, timer, different program call) the program receives control (in some other thread or in special routine). Somehow the sleep in wait_for_events becomes interrupted and wait_for_events returns.
On that occurrence of control the event handler stores information of that event into some data structure, events, which later is used for doing something about that events (event->process). There can happen not only one, but many events in the time between entering and exiting of wait_for_events, all of them must be processed. The event->process() procedure is custom and should usually call the interesting part - user's twisted code.