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

Chain

The chain function takes task signatures and passes the value of each result to the next value in the chain, returning one result, as follows:

>>> from celery import chain
>>> sig = chain(multiply.s(10, 10), multiply.s(4), multiply.s(20))
# same as above
>>> sig = (multiply.s(10, 10) | multiply.s(4) | multiply.s(20))
>>> result = sig.delay()
>>> result.get()
8000
  

Chains and partials can be taken a bit further. Chains can be used to create new functions when using partials, and chains can be nested as follows:

# combining partials in chains >>> func = (multiply.s(10) | multiply.s(2)) >>> result = func.delay(16) >>> result.get() 320# chains can be nested >>> func = ( multiply.s(10) | multiply.s(2) | (multiply.s(4) | multiply.s(5)) ) ...
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