'Linux/pm2 is killing my Flask service using Python's multiprocessing library

I have a Flask service running on a particular port xxxx. Inside this flask service is an endpoint:

/buildGlobalIdsPool

This endpoint uses Python's multiprocessing library's Pool object to run parallel processes of a function:

with Pool() as p:
    p.starmap(api.build_global_ids_with_recordlinkage, args)

We use pm2 process manager on a Linux server to manage our services. I am hitting the endpoint from Postman and everything works fine up until the code above is reached. As soon as processes are supposed to spawn, pm2 will kill the main Flask process, but the spawned processes will persist (I check using lsof -i:xxxx and I see multiple python3 processes running on this port). This happens whether I run the service using pm2 or if I simply run python3 app.py. My program works on my local Windows 10 machine.

Just curious what I could be missing that is native to Linux or pm2 that is killing this process or not allowing multiple processes on the same port, while my local machine handles the program just fine.

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source