- Event loop: You can think of an event loop as something like a
while True
loop that monitors coroutines, taking feedback on what’s idle, and looking around for things that can be executed in the meantime. It is able to wake up an idle coroutine when whatever that coroutine is waiting on becomes available. asyncio.run()
, introduced in Python 3.7, is responsible for getting the event loop, running tasks until they are marked as complete, and then closing the event loop.- Coroutines don’t do much on their own until they are tied to the event loop.
- By default, an async IO event loop runs in a single thread and on a single CPU core. Usually, running one single-threaded event loop in one CPU core is more than sufficient. It is also possible to run event loops across multiple cores.
async for
does not automatically parallelize the iterations. Instead it simply allows sequential iteration over an async source. Use case for using "async for" is to iterate(without blocking the event loop) over the lines coming from a TCP stream, msgs from a websocket or DB records from an async DB driver.- Python’s
requests
package isn’t compatible with async IO.requests
is built on top ofurllib3
, which in turn uses Python’shttp
andsocket
modules. By default, socket operations are blocking. This means that Python won’t likeawait requests.get(url)
because.get()
is not awaitable. In contrast, almost everything inaiohttp
is an awaitable coroutine, such assession.request()
andresponse.text()
.requests
is a great package otherwise, but you should not userequests
in asynchronous code. - You can use
asyncio.create_task()
to schedule the execution of a coroutine object, followed byasyncio.run()
asyncio-trials's Introduction
asyncio-trials's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.