Sphere
Log in Join
☆ 18

FastAPI endpoint freezes the whole server during image resize

My upload endpoint resizes images with Pillow. One request blocks every other request for 2 seconds. The endpoint is async def. I thought async made this concurrent.

⚑ Report

3 replies

☆ 0
J Jordan ·2026-09-29#1

Async only helps while waiting on I/O. Pillow is CPU work, so it occupies the event loop. Offload it with run_in_executor or a separate worker.

⚑ Report
☆ 0
O Oskar ·2026-09-29#2

I tried ProcessPoolExecutor but pickling the image was slow. Is threading enough?

⚑ Report
☆ 0
J Jules R. ·2026-09-30#3

Try a ThreadPoolExecutor first. Pillow releases the GIL for much of its work, so threads often help and avoid the copy cost. If it is still slow, move resizing to a queue.

⚑ Report
Log in to reply.