Grokking Concurrency in Python
Vote

0% completed

​

Asyncio on the Free-Threaded Build

def crawl_in_thread(numbers): return asyncio.run(crawl(numbers))

That function gives each thread its own asyncio event loop. Harvest's async crawler, which fetches pages and indexes them, needed 0.95 seconds for 16 pages with one loop on the free-threaded build. With 8 threads each running that function, it needed 0.50 seconds. On the standard build, the same 8 loops took 1.00 seconds, slightly slower than one loop.

The free-threaded build lets several event loops run Python code at the same instant, but it does not change what a loop is or which objects belong to it

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content