Grokking Concurrency in Python
Vote

0% completed

​

Async Code Inside Sync Code

How should an ordinary thread call a coroutine? The obvious answer is asyncio.run(coro), which starts an event loop, runs the coroutine, and returns its result. It fails when several threads make such calls at once and share an async object, because each call creates its own event loop.

Harvest has exactly this arrangement. Its indexing workers are ordinary threads, and its only page fetcher is async, protected by an asyncio.Semaphore that allows four requests to the site at once.

Why asyncio.run per Call Fails

`asyncio.run

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content