logoalt Hacker News

kccqzyyesterday at 4:41 PM4 repliesview on HN

Forking and multi threading do not coexist. Even if one of your transitive dependencies decides to launch a thread that’s 99% idle, it becomes unsafe to fork.


Replies

rpcope1yesterday at 5:28 PM

Im curious as to the down votes on this. It's absolutely true, and when I was maintaining a job runner daemon that ran hundreds of thousands of who knows what Python tasks/jobs a day on some shared infra with arbitrary code for a certain megacorp from 2016-2020 or so, this was one of insidious and ugly failure modes to go debug and handle. The docs really make it sound like you can mix threading and multiprocessing but you can never really completely ensure that threading and then bare fork will ever be safe, period. It's really irritating that the docs would have you believe that this is OK or safe, but is in keeping with the Python philosophy of trying to hide the edge of the blade you're using until it's too late and you've cut the shit out of yourself.

akdev1lyesterday at 5:44 PM

Why is it unsafe?

show 1 reply
LtWorfyesterday at 8:33 PM

I'm replying to a person that scales python by running several containers instead of 1 container with several python processes.

philsnowyesterday at 5:26 PM

Fork-then-thread works, does it not?

show 2 replies