liveBook · Manning

Callback

As explained in Fast Python: High performance techniques for large datasets

A callback is a function or other callable supplied to software for invocation later in response to a specified event, condition, or point in execution.

A callback is a user-supplied function invoked by another operation at a defined point. In asynchronous MapReduce, callbacks report job progress; their required arguments follow the reporting function’s protocol. section 3.3.2

Progress callbacks differ in when they run:

  • A futures-based implementation calls the callback periodically while map or reduce jobs are running, passing a tag and counts of completed and remaining tasks. section 3.3.2
  • The multiprocessing pool’s map_async callback runs only when all results are ready; per-item progress requires a lower-level approach that checks individual results. section 3.4.3
  • Keep callbacks fast: execution waits for them. A callback’s return value could also be used to support cancellation. section 3.3.2
def reporter(tag, done, not_done):
    print(f'Operation {tag}: {done}/{done+not_done}')

A minimal reporter prints the operation tag and completed-task count. section 3.3.2

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Explains callback timing, arguments, and performance implications, contrasting periodic reporting with completion-only notification.
Examples
Uses a reporter that prints map or reduce progress and contrasts it with map_async completion notification.
What it assumes
Assumes familiarity with asynchronous map and reduce jobs, while specifying the callback’s required arguments.
What you can do after
Apply callbacks to report completed and remaining tasks during asynchronous MapReduce execution.
How it connects
Connects callbacks to futures, multiprocessing pools, asynchronous execution, and MapReduce progress tracking.

Also explained in

Compare how 19 books explain callback →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.