Some concepts about asynchrony

recently I learned about the tornado framework, so I heard a saying that not all python libraries support asynchronism. OK, so think of it. It may be said that if a child thread or a child process is running this code at the same time, either there will be no variables operating at the same time, or the variables will be locked. I wonder if the code that supports async and thread safety here is trying to say the same thing?

May.31,2022

async and thread safety are two concepts in different domains.

Asynchronous

give an example of synchronization

f1()
f2()
f3()

this call mode makes the code only execute sequentially. Assuming that the F1-3 call takes 3 seconds, respectively, it takes 1 "2" 3 minutes 6 seconds.

and the asynchronous call may be like this

task1 = async_f1()
task2 = async_f2()
task3 = async_f3()
gather(task1, task2, task3)

it only takes 3 seconds to execute, because three calls can be made at the same time.

Thread safety

take a function as an example. Thread safety means that when multiple threads are called at the same time, there will be no conflict between threads.


there is a premise here at the business logic level, while the system IO is usually synchronous.
Asynchronous is returned directly after the call is made, and the result has to wait for the status of the called or callback notification.
the common result = some_function (xxx) obviously waits for the result, so asynchronous calls cannot be directly supported.
Thread safety and async obviously don't mean the same thing.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7c13f9-1f99e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7c13f9-1f99e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?