Closed junbaibai0719 closed 2 years ago
I didn't run the code but this most probably happens because _instance_lock = threading.Lock()
gets created in the master server process and then gets shared between all the spawned children processes.
You can try removing with DbUtil._instance_loc:
and see what happens.
I see!I always thought the lock would be created in children process,It is actually created when the class is defined.
I use asyncio.Lock and succeed. If using threading.Lock,the children process will blocking themselves, because DbUtil._instance = await aiomysql.create_pool
.
when i set multi process, only one run.
code
while i request 127.0.0.1:8081/, proccessor id
27719 27716 27710 27722 27719 27716 27710 27722 27719 27710 27716 27722 27719 27710 27716
while i request 127.0.0.1:8081/hello, proccessor id
27711 27711 27711 27711 27711 27711 27711 27711 27711 27711 27711 27711 27711 27711 27711 27711