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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.