Using asyncio to implement coroutines
Asyncio is the default implementation in Python of an event loop for asynchronous input/output operations. An event loop is a pattern that solves the problem of concurrent access to shared resources. In 1965, the famous computer scientist Edsger W. Dijkstra formulated a problem called ‘The dining philosophers’, which goes something like this:
Five philosophers dine together at the same table. Each philosopher has their own plate at the table. There is a fork between each pair of adjacent plates. The dish served is a kind of spaghetti which has to be eaten with two forks. Each philosopher can only alternately think and eat. Moreover, a philosopher can only eat their spaghetti when they have both a left and right fork. Thus, two forks will only be available when their two nearest neighbors are thinking, not eating. After an individual philosopher finishes eating, they will put down both forks.
(Wikipedia: https:...