T
T
toddbarry2018-07-20 17:32:05
Asynchronous programming
toddbarry, 2018-07-20 17:32:05

What problems can arise with aiohttp?

All the same, aiohttp is an asynchronous framework, but it was not possible to catch typical incidents of asynchrony.
So I don't really understand how it works?
Let's say I want to calculate the variable b, which is simply equal to the variable a on the backend, which in turn is taken from the base.
The way it will happen is as follows: there is a corrutina in which b=a is assigned by launching another subroutine that executes a query to the database - climbs there for the variable a.
These tasks are separated and fall into the event loop as different. And the subroutine which climbs in base is defined at first. Obviously, it will take longer than a simple assignment to b=a, so the event loop will jump right into the assignment. Means processing is not similar to synchronous. How it works? Everywhere they write that aiohttp allows you to run asynchronous workers and at the same time write code as if it were synchronous.
Can I fully rely on this statement?
Should there be any stipulations? To improve performance, is it better to write corrutins small and split tasks into a bunch of subroutines? Or, on the contrary, is it better to shove everything into one corrutinum?
I'm sorry, I'm just a little confused

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-07-20
@sergey-gornostaev

Everywhere they write that aiohttp allows you to run asynchronous workers and at the same time write code as if it were synchronous.

They write garbage.
No, the entire chain of asynchronous calls from the code that accepted the client connection to the code crawling into the database will stop waiting for data, and the event loop will continue to serve other chains and check the readiness of the data at the next iteration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question