0

Based on CPython.

I'm new to python asyncio (and also similar nodejs, etc).

I've heard that the python asyncio is not based on thread, thus leaving it free of thread-related problems such as two write operations at the same time. As I know the GIL provides 'some kind of' thread-safety based on bytecode in CPython ie, each bytecode is atomic. Now my question. At what atomic unit does the python asyncio provides the atomic execution of a python script?

For example, one feasible(not that I'm saying it is reasonable) answer is that each line in python script is atomic. I think I can use this to handle the race condition of concurrent async corutines.

Thanks for your help, please tell me if I miss something.

I took a look at python docs. no luck.

김꼬막
  • 1
  • 1
  • asyncio is not thread safe. It runs all async routines in a single thread and those routines only yield to each other explicitly. But a different thread can still interfere. This is the risk of bolting async on a sync system. – tdelaney Dec 21 '22 at 02:40
  • @tdelaney Thanks! I edited my question. Sorry that I wasted your time. You made a valid point. – 김꼬막 Dec 21 '22 at 10:38

0 Answers0