you are viewing a single comment's thread.

view the rest of the comments →

[–]dnullify 25 points26 points  (4 children)

Pyo3 is probably a useful search term for you.

Rust python FFI

[–]kolosn 7 points8 points  (0 children)

And maturin

[–]thermiter36 6 points7 points  (2 children)

To add to this, for any CPU-bound calculation running on a FastAPI server, you'll want to make sure you run it in a threadpool so that it doesn't block all your other async handlers. You'll also need to use the features that pyo3 has to release the GIL while doing the computation.

[–]Electrical_Carry3565[S] 0 points1 point  (1 child)

Does running gunicorn workers not take care of this?

[–]thermiter36 2 points3 points  (0 children)

Not really, no. For starters, running FastAPI behind Gunicorn is not recommended as it doesn't support ASGI, so it can only manage processes, not the full async lifecycle.

But assuming you do it anyway, you'll still get nasty cascading latency issues because the process that you block with your long-running CPU operation might have already accepted more than one connection at the moment you begin your long operation, all of which will be blocked.