Open tyilo opened 2 years ago
import asyncio
from threading import Thread
import uvloop
def create_processes(i):
async def inner():
processes = []
for _ in range(100):
p = await asyncio.create_subprocess_exec("true")
processes.append(p)
for p in processes:
await p.wait()
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(inner())
print(f"[{i}] Success.")
except Exception as e:
print(f"[{i}] Fail: {repr(e)}")
def main():
threads = []
for i in range(10):
t = Thread(target=lambda: create_processes(i))
t.start()
threads.append(t)
for t in threads:
t.join()
if __name__ == "__main__":
uvloop.install()
main()
0.17.0
3.10.8
PYTHONASYNCIODEBUG
in env?: YesWe have a multi-threaded application using
uvloop
that sometimes needs to spawn a lot of processes simultaneously. This results in a lot of "RuntimeError: Racing with another loop to spawn a process" exceptions being raised.The following is a minimal reproducible example that shows the problem:
When running this with
PYTHONASYNCIODEBUG=1
I get something like:Without
uvloop
I get something like: