How To Make ANY Function Asynchronous In Python 3.12

preview_player
Показать описание
In this tutorial I will be showing you how you can turn any normal function into an asynchronous function in Python. This can be particularly useful with the requests module if you don't want to wait for a request to complete one at a time.

▶ Become job-ready with Python:

▶ Follow me on Instagram:
Рекомендации по теме
Комментарии
Автор

I literally just did this and pulled up YouTube because I finished. Crazy ahh timing
Specifically I used ansycio to preform multiple network requests.

TheBomb
Автор

There's also the lower level 'loop.run_in_executor' that allows you to specify the 'concurrent.future.Executor' you want to run on. But that's more advanced and should be used only when you really need it ('to_thread' just calls this function, while setting up contextvars)

uKaigo
Автор

in your example, asynchrony itself is poorly shown, because you did not use gather, and what you did was just run the task in another thread, this has existed since python 3.9

htry
Автор

Very interesting. Despite Python being my bread and butter, I never had to use it for async/await. When I had the requirement some time ago... I happened to be working in a Go environment, where this sort of thing is arguably one of its strongest suits. What I find even more interesting is that, just as in C#, it's "async all the way up", something I always found a bit annoying when you only have certain parts of your code that needs to be async. There's ways around it, but it requires using the async/await (asyncio) framework with some wrapping code that I always found a bit, I dunno, ugly, I guess.

michaelhoffmann
Автор

Thanks for the tutorial, I always get stuck on async functions

AmineGM
Автор

Thanks for such a beautiful and easy explaination sir .

dolla_shrey
Автор

I was needed broh! Thank you so much. 💯

dipeshsamrawat
Автор

Thanks!
Can we archive the same result using thread pool ?

ilanbar
Автор

good video thx you so much plz made threading and threadPool all types and processes also.

abdullahsaid
Автор

shoud you always use async? or is there specific use cases for it?

imusinghuzuni
Автор

Another good video. Thank you, signor :)

elatedbento
Автор

Just a heads up. Your microphone picks up the vibrations of the table when you type on the keyboard. You can hear it when listening with headset.

Johannes
Автор

i think you did not run them asynchronously as although they started more or less at the same time, but the code waited for apple to finish first and then waited for google to finish. Please correct me if i am wrong.

lovekesh
Автор

What is the difference between asyncio, multithreading and multiprocessing. These things do the same thing, don't they?

Smart_Coder
Автор

Great Video! Would you (or anyone else for that matter) mind telling me which text editor you are using?

wannich
Автор

I did many research on this in past but no one really taught it well and in such simple way. Yeah but I think the tasks should be non interdependent for the functions to works asynchronously.

dolla_shrey
Автор

Naked `dict` type is not the best thing, please specify key/value types or let mypy infer the types.

senyai
Автор

When importing a complete module, as you did with asyncio and requests: why bother to then import something else explicit (like Response) instead of referring to it using the already imported module (like requests.Response) as you do with everything else (see requests.get(…) for example)?

iham
Автор

If I am using django, and I need to do some extra work such as run some utility function or something, this can be used there too right?

ritankarbhattacharjee
Автор

We can use celery for seperate thread task na? Sorry if my question is wrong.

abdulnafihkt
welcome to shbcf.ru