Event-driven programming
Event-driven programming is a paradigm of system architecture where the logic flow within the program is driven by events such as user actions, messages from other programs, or hardware (sensor) inputs.
In Event-driven architectures, there is usually a main event loop, which listens for events, and then triggers callback functions with specific arguments when an event is detected.
In modern operating systems like Linux, support for events on input file descriptors such as sockets or opened files are implemented by system calls such as select
, poll
, and epoll
.
Python provides wrappers to these system calls via its select
module. It is not very difficult to write a simple Event-driven program using the select
module in Python.
The following set of programs together implement a basic chat server and client in Python using the power of the select module.
Chat server and client using I/O multiplexing with the select module
Our chat server uses the select
system call via the...