Examples in Python

Let's look at a specific implementation of the concurrent.futures module. Recall that in this chapter's first example (the counting down example), the blocking time.sleep() function prevented our asynchronous program from becoming truly asynchronous, and had to be replaced with its non-blocking version, asyncio.sleep(). Now, we are executing the individual countdowns in separate threads or processes, which means that the blocking time.sleep() function will not pose any problems in terms of executing our program asynchronously.

Navigate to the Chapter10/example5.py file, as follows:

# Chapter10/example5.pyfrom concurrent.futures import ThreadPoolExecutorimport asyncioimport timedef count_down(name, delay): indents = (ord(name) ...

Get Mastering Concurrency in Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.