flask-executor icon indicating copy to clipboard operation
flask-executor copied to clipboard

Support Loky executors?

Open jtlz2 opened this issue 6 years ago • 2 comments

I am trying to make parallel process calls to opencv functions, which are currently suffering from this issue: https://github.com/opencv/opencv/issues/5150#issuecomment-400727184

A suggested workaround is to get the Process executors from Loky.

Out of the box Loky runs into context problems with Flask, which is how I ended up here.

Could flask-executor be made to work with Loky and so open the door for parallel processing of opencv calls within Flask?

Thanks for all help

jtlz2 avatar Sep 23 '19 12:09 jtlz2

In executor.py I tried to replace concurrent.futures.ProcessPoolExecutor with loky.get_reusable_executor, but this throws up context problems:

RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
to interface with the current application object in some way. To solve
this, set up an application context with app.app_context().  See the
documentation for more information.

jtlz2 avatar Sep 23 '19 13:09 jtlz2

I am tracking this in a SO question at https://stackoverflow.com/questions/58093735/flask-how-do-i-successfully-use-multiprocessing-not-multithreading

So far I can get flask-executor working well, but without opencv. Assuming Loky can handle the latter problem, can flask-executor be made to work with Loky? What magic is Loky providing that flask-executor doesn't?

Thanks!

jtlz2 avatar Sep 25 '19 09:09 jtlz2

I expect this to no longer be an issue, given recent changes that wrap each callable in a new application context.

dchevell avatar Aug 19 '22 10:08 dchevell