When Utils().thumbnail tries to cache an image whose raw data is large enough, the kernel just terminates the whole uvicorn process due to insufficient memory.
After some inspection, it turned out that I never properly closed the PIL image or the buffer after opening an image, which may take up extra memory (perhaps, I’m not really that good with memory related stuff).
And the root cause is actually related to how large some images can be when dealing with their uncompressed versions. Since PIL works with the raw data of images, a 9MB image can go all the way up to >100MB in memory.
When Utils().thumbnail tries to cache an image whose raw data is large enough, the kernel just terminates the whole uvicorn process due to insufficient memory.
After some inspection, it turned out that I never properly closed the PIL image or the buffer after opening an image, which may take up extra memory (perhaps, I’m not really that good with memory related stuff).
And the root cause is actually related to how large some images can be when dealing with their uncompressed versions. Since PIL works with the raw data of images, a 9MB image can go all the way up to >100MB in memory.