Flask extension to defer task execution under after request teardown
Project description
Flask-Defer
=========
.. image:: https://badge.fury.io/py/flask-defer.svg
:target: https://badge.fury.io/py/flask-defer
.. image:: https://travis-ci.org/brettlangdon/flask-defer.svg?branch=master
:target: https://travis-ci.org/brettlangdon/flask-defer
Easily register a function to execute at the end of the current request.
Installation
~~~~~~~~~~~~
.. code:: bash
pip install Flask-Defer
Usage
~~~~~
Passing a function and it's arguments to `flask_defer.after_request` will register that function to execute when the Flask request has ended.
If a call to `flask_defer.after_request` happens outside of a request context then the function will be executed immediately.
.. code:: python
from flask import Flask
from flask_defer import FlaskDefer, after_request
app = Flask(__name__)
FlaskDefer(app)
def defer_me(name, say_hello=False):
if say_hello:
print 'Saying hello to, {name}'.format(name=name)
@app.route('/')
def index():
print 'Start of request method'
# Defer `defer_me` until after the current request has finished
after_request(defer_me, 'name', say_hello=True)
print 'Ending request method'
return 'Thanks!'
if __name__ == '__main__':
app.run()
.. code:: bash
$ python example.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Start of request method
Ending request method
Saying hello to, name
127.0.0.1 - - [28/Nov/2016 15:41:39] "GET / HTTP/1.1" 200 -
=========
.. image:: https://badge.fury.io/py/flask-defer.svg
:target: https://badge.fury.io/py/flask-defer
.. image:: https://travis-ci.org/brettlangdon/flask-defer.svg?branch=master
:target: https://travis-ci.org/brettlangdon/flask-defer
Easily register a function to execute at the end of the current request.
Installation
~~~~~~~~~~~~
.. code:: bash
pip install Flask-Defer
Usage
~~~~~
Passing a function and it's arguments to `flask_defer.after_request` will register that function to execute when the Flask request has ended.
If a call to `flask_defer.after_request` happens outside of a request context then the function will be executed immediately.
.. code:: python
from flask import Flask
from flask_defer import FlaskDefer, after_request
app = Flask(__name__)
FlaskDefer(app)
def defer_me(name, say_hello=False):
if say_hello:
print 'Saying hello to, {name}'.format(name=name)
@app.route('/')
def index():
print 'Start of request method'
# Defer `defer_me` until after the current request has finished
after_request(defer_me, 'name', say_hello=True)
print 'Ending request method'
return 'Thanks!'
if __name__ == '__main__':
app.run()
.. code:: bash
$ python example.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Start of request method
Ending request method
Saying hello to, name
127.0.0.1 - - [28/Nov/2016 15:41:39] "GET / HTTP/1.1" 200 -
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-Defer-1.0.1.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for Flask_Defer-1.0.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac91934ff33b30f7d9ae0b27c9c3db428fdad335914fff0ed4a19790a383dc2d |
|
MD5 | a25505c1bbf4630c91a7d55900b20d61 |
|
BLAKE2b-256 | 62fb06309e128cf01e5050fe1d9197071b07937542480d7216bf7fbf99e026a3 |