1

I'm writing a little app in python, consuming some http services, but i really don't understand the difference between using an async function or an Thread for consuming that services.

Anyone can help me to understand?

2 Answers2

0

I have been reading up on the threaded model of programming versus the asynchronous model from this really good article. http://krondo.com/blog/?p=1209

However, the article mentions the following points.

  1. An async program will simply outperform a sync program by switching between tasks whenever there is a I/O.
  2. Threads are managed by the operating system.

I remember reading that threads are managed by the operating system by moving around TCBs between the Ready-Queue and the Waiting-Queue(amongst other queues). In this case, threads don't waste time on waiting either do they?

In light of the above mentioned, what are the advantages of async programs over threaded programs?

moe asal
  • 750
  • 8
  • 24
0

In a function there is an entry point and there is an exit point (which is usually a return statement or last statement of function).

Thread: executes all the possible statements from entry point to exit point.

async function :

Functions defined with async def syntax are always coroutine functions

This is from python reference documentation. And coroutines can be entered,exited or resumed from different points anywhere between entry and exit point of the function.

Now, based on your requirement, you can choose which one to use.

Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
  • 1
    thanks for comment. after reading a little more i found, in my words: "async functions wait for something to happen (spending the time) meanwhile threads do many things parallely" – Andrés Mauricio Gómez Sep 13 '19 at 23:12