An easy to use Flask wrapper for concurrent.futures
Likely abandoned. No release or commit for years (last release over 4 years ago).
pip install flask-executorFlask-Executor
Sometimes you need a simple task queue without the overhead of separate worker processes or powerful-but-complex libraries beyond your requirements. Flask-Executor is an easy to use wrapper for the concurrent.futures module that lets you initialise and configure executors via common Flask application patterns. It's a great way to get up and running fast with a lightweight in-process task queue.
Installation
Flask-Executor is available on PyPI and can be installed with:
pip install flask-executor
Quick start
Here's a quick example of using Flask-Executor inside your Flask application:
from flask import Flask
from flask_executor import Executor
app = Flask(__name__)
executor = Executor(app)
def send_email(recipient, subject, body):
# Magic to send an email
return True
@app.route('/signup')
def signup():
# Do signup form
executor.submit(send_email, recipient, subject, body)
Contexts
When calling submit() or map() Flask-Executor will wrap ThreadPoolExecutor callables with a
copy of both the current application context and current request context. Code that must be run in
these contexts or that depends on information or configuration stored in flask.current_app,
flask.request or flask.g can be submitted to the executor without modification.
Note: due to limitations in Python's default object serialisation and a lack of shared memory space between subprocesses, contexts cannot be pushed to ProcessPoolExecutor() workers.
Futures
You may want to preserve access to Futures returned from the executor, so that you can retrieve the results in a different part of your application. Flask-Executor allows Futures to be stored within the executor itself and provides methods for querying and returning them in different parts of your app::