# Lesson 2- Eventloops

* call\_soon
* call\_later
* run\_forever - loops

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-MiNN9_pa0pXbWthn_e7%2F-MiNNXmw1pz0i3CapTrm%2Fimage.png?alt=media\&token=9dbe3a98-c852-4cba-a108-c58b903e9a2e)

Select operations

Eventloops can run only one things at a time. There is usually a :

selector or proactor

Reactors - reacts based on notifications used by reactors

twisted calls eventloops

I/0 completion Ports - changes. In windows you can use proactors and selctors. In Unix you can use selectors

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-Mj2K3S86a3zlK49S08Z%2F-Mj2KnVUeZHGAV5w1iF-%2Fimage.png?alt=media\&token=22caca50-e229-45c5-badd-3bb3ac529aa3)

Base\_events - consists of base events, yet there is only while loops there

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-Mj2K3S86a3zlK49S08Z%2F-Mj2N7F1aFQXjBgOKSY-%2Fimage.png?alt=media\&token=c7960704-cd37-415a-9a91-152d05ef86e2)

Python 3.5 implementation, then in \`*run*once\`

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-Mj2K3S86a3zlK49S08Z%2F-Mj2NMmhvUXVvkd4_HTm%2Fimage.png?alt=media\&token=db36d931-69af-4311-8dca-d5081b3997ae)

Heart of heart of asyncio is select\_once method which calls the proactors and is having selector.select(timeout) method

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-Mj2K3S86a3zlK49S08Z%2F-Mj2O9k_kzQoIArmTQs9%2Fimage.png?alt=media\&token=8f85df27-4725-416f-b8b7-d4a9338f9fe1)

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-Mj2K3S86a3zlK49S08Z%2F-Mj2OKkm6F5F_wc8n3kL%2Fimage.png?alt=media\&token=811d9b52-0b89-475a-8b5f-f9132151baf1)

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-Mj2K3S86a3zlK49S08Z%2F-Mj2OLiTA_ZjKkwfQjmo%2Fimage.png?alt=media\&token=8442f823-eb7e-4e6e-b694-f155d9db6340)

Uvloop for production, as it's doing a lot of magic and improvement in results. As it's fastest implementation with similar performance to NodeJS

Eventloop is just a normal function for handling netoworks requests and is used to handle callbacks. By what?

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-Mj2K3S86a3zlK49S08Z%2F-Mj2Pledle4i1Vyi9898%2Fimage.png?alt=media\&token=d1159ac3-1e94-4dff-af76-925807d6281d)

Eventloop is not magical, it's just a loop which handles network events and executes as callbacks one by one. It can handle many networks events concurrently with a selector or a proactor. While it can handle many callback, but only run one callback at a time. Some callbacks, run and come again with a trick called traumpaline

callsoon, calllater is difficult to run. But it's usually run using coroutine. These coroutines make asynchrnous programs easy and magical


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.kurianbenoy.com/async-await/lesson-2-eventloops.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
