A program does not live alone. The operating system can ask it to stop with a signal, hand it an environment, and tell it what machine it is on. And a server that must watch many connections can ask the system which of them is ready, which is the idea beneath asyncio. This lesson covers all three: signals and graceful shutdown, the selectors module, and the way to ask about the system without breaking portability.
More lessons in Complete Python Programming