python - Threads vs. Async - Stack Overflow
https://krondo.com/in-which-we-begin-at-the-beginning/
与threading相比, async的优势表现为3点:
- It is very difficult to write code that is thread safe. With asyncronous code, you know exactly where the code will shift from one task to the next and race conditions are therefore much harder to come by.
- Threads consume a fair amount of data since each thread needs to have its own stack. With async code, all the code shares the same stack and the stack is kept small due to continuously unwinding the stack between tasks.
- Threads are OS structures and are therefore more memory for the platform to support. There is no such problem with asynchronous tasks.
大致意思:
1. 代码很难保证线程时安全的,而async 代码,可以很清楚的看到代码之间的调换/执行过程
2.每个线程有自己单独的栈,而async代码之间共享栈
3. 线程比较耗内存