Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Partials

The first application of task signatures is functional programming style partials. Partials are functions, which originally take many arguments, but an operation is applied to the original function to return a new function, so the first n arguments are always the same. Consider the following example, where we have a multiply function that is not a task:

>>> new_multiply = multiply(2)
>>> new_multiply(5)
10
# The first function is unaffected
>>> multiply(2, 2)
4
  

This is a fictional API, but is very close to the Celery version:

>>> partial = multiply.s(4)
>>> partial.delay(4)

The output in the worker window should show 16. Basically, we created a new function, saved to partial, that will always multiply its input by four.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content