How to make hypercorn workers restart when they die

257 views Asked by At

I previously used gunicorn with uvicorn and other types of workers.

I'm switching to hypercorn but you have roll your own process management.

I am comfortable with ProcessPoolExecutor pools, but I can't get it to work with the uvloop_worker in hypercorn.

This works fine without restart capability:

for _ in range(config.workers):
     process = Process(
         target=uvloop_worker,
         kwargs={"config": config,"shutdown_event": shutdown_event, "sockets": config.create_sockets()},
     )
     process.daemon = True
     process.start()
     processes.append(process)

But i want the workers to restart if one dies (like gunicorn does), so i tried:

kwargs = {"config": config,"shutdown_event": shutdown_event, "sockets": config.create_sockets()}
with Pool(max_workers=config.workers) as pool:
    pool.name = f"hypercorn_worker"
    worker = partial(uvloop_worker , **kwargs)
    results = pool.map(worker, [None]*1000)

and i get:

RuntimeError: Condition objects should only be shared between processes through inheritance
0

There are 0 answers