1

curio library provides async aopen() function, while pillow has it's own Image.open. I want to create thumbnail and suggest pillow is smart enough not to load all image into memory while creating thumbnail. It looks like this:

self.image = Image.open(path)
self.image.thumbnail((300, 300))

How this can be integrated with the curio library? For me it looks like I have two options:

  • Call aopen(), load data into memory, then create Image object from in-memory data and call Image.thumbnail()
  • Make Image.open() async wrapping with async_thread decorator, but it requires fire all thread machinery.

Is there some better approach for integrating curio and pillow for this task?

likern
  • 3,744
  • 5
  • 36
  • 47
  • Are you sure that opening the file is slow enough to worry about it? In what context is this? – syntonym Mar 21 '18 at 20:03
  • @syntonym It's not only about opening one or several files. It's about how to integrate async library with **pillow** for efficient use. Also it might be required to generate thumbnails for all (or major part of) files beforehand, for example in inserted SD-card from photo camera. – likern Mar 22 '18 at 14:16
  • Opening a single file should be so fast that using async IO for that is not needed. Opening many files should be IO bound so that using async IO shouldn't give you a speed boost. If you are webserver than of course the time you open files syncronously you can't answer requests, which would be one reason to use async IO. I think the "correct way" depends on your context. `aopen()` is implemented as `run_in_thread`: https://github.com/dabeaz/curio/blob/master/curio/file.py#L84 – syntonym Mar 25 '18 at 09:27
  • @syntonym 1. I want to know how to integrate these two libraries anyway, because I use both. 2. When I call `Image.open()` I get `Image` object, from which I can create thumbnail (I'm pretty sure it doesn't load whole 20Mb picture into memory for that). 3. Implementation of `aopen()` might be changed in the future as soon as general AIO will be added into linux kernel. – likern Mar 25 '18 at 10:49

0 Answers0