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

Executor gets "stuck" with a RuntimeError

Open justin1364 opened this issue 4 years ago • 0 comments

First, this is an insanely useful repo –– thanks!

Everything is working great in my code except for a weird situation in which my Flask app tries to do this:

@app.route("/do_work")
def do_work_route():
    executor.submit(
        my_function,
       my_argument)

    return "Doing work.", 200

And sometimes this results in:

  File "/Users/justin/venv/rloo/lib/python3.7/site-packages/flask_executor/executor.py", line 162, in submit
    future = self._self.submit(fn, *args, **kwargs)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 153, in submit
    raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown

Which is persistent until I restart the app completely. Locally I can repro the issue by hitting the do_work_route(), changing code which auto-reloads before my_function() completes, and then I get the persistent RuntimeError.

However, on my production machine, which is running gunicorn, I'm seeing the same persistent error, and I'm not sure how it started.

I'm not sure if this is helpful, but my_function() is running long-running Postgres queries with psycopg2.

justin1364 avatar Apr 25 '20 19:04 justin1364