Skip to main content

ci Coverage PyPI version

mpmq

mpmq is a Python package for running the same function across multiple processes while capturing worker log messages in a central message queue. It is built for programs that need controlled parallel execution, per-worker inputs, and a clean way to observe what workers are doing while they run.

Why use mpmq

Raw multiprocessing gives you processes, but you still end up writing glue code for:

  • feeding each worker input
  • limiting concurrency
  • collecting results
  • handling worker logs

mpmq handles that for you with a simple, consistent execution model.

What mpmq does

mpmq runs a function across multiple processes, passing each worker its own input and optionally shared data. Worker log messages are routed back to the parent process through a queue, and results are collected when execution completes. You define the work and inputs. mpmq handles process management, concurrency, message forwarding, and result collection.

mpmq is a lightweight wrapper around Python multiprocessing that lets you run a function across multiple processes, centralize worker log messages, and collect results — without writing the plumbing yourself.

Installation

pip install mpmq

MPmq class

mpmq.MPmq(function, process_data=None, shared_data=None, processes_to_start=None)

Parameters

function

Function executed in each worker process.

process_data

List of dictionaries. Each dictionary is passed to one worker. Total length = total executions.

shared_data

Dictionary passed to all workers.

process_to_start

Max number of concurrent workers. Extra work is queued and executed as workers complete.

Methods

execute(raise_if_error=False)

Starts execution and waits for all workers to complete.

Returns a list of results from each worker.

If raise_if_error=True, raises an exception if any worker fails.

process_message(offset, message)

Hook for handling log messages from workers while execution is running.

  • offset - index of worker in process_data
  • message - logged message

This is the key extension point for building tools like progress displays or terminal UIs.

Examples

The MPmq class is designed to be subclassed. By overriding process_message, you can handle log messages from worker processes as they are received. The example below shows how to do this.

Worker Status as a Progress Bar

The example parallizezes a task across multiple processes using a pool of worker processes. Status of each worker is shown as a Progress Bar, as each Child worker in the pool completes an item defined in the task the Parent updates a Progress Bar.

example

Worker Status as a List

The example parallizezes a task across multiple processes using a pool of worker processes. Status of each worker is shown using an array where each index of the array represents an individual worker, as each Child worker in the pool completes the associated item in the List is updated with the completed message.

example

Projects using mpmq

  • mpcurses An abstraction of the Python curses and multiprocessing libraries providing function execution and runtime visualization capabilities

  • mppbars Scale execution of a function across multiple across a number of background processes while displaying their execution status via a progress bar

  • mp4ansi A simple ANSI-based terminal emulator that provides multi-processing capabilities

Development

Clone the repository and ensure the latest version of Docker is installed on your development server.

Build the Docker image:

docker image build \
-t mpmq:latest .

Run the Docker container:

docker container run \
--rm \
-it \
-v $PWD:/code \
mpmq:latest \
bash

Execute the build:

make dev

Metadata

Release files for mpmq 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mpmq 0.7.0
File Size Uploaded
mpmq-0.7.0.tar.gz 16.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mpmq 0.7.0
File Interpreter ABI Platform
mpmq-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.9 kB

Release files / mpmq-0.7.0.tar.gz

Download URL mpmq-0.7.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5e57935d7488fe10b4ba14b499124c65eacf0af354662dc5f03b1b70cb0defde
BLAKE2b-256 checksum
How to use checksums
80c510bc12a01e8ae23527cd37ac0b6adbf75cffabab2f654313de7322fbb2b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / mpmq-0.7.0-py3-none-any.whl

Download URL mpmq-0.7.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40642ae647ee022c0feeeab37d9af5858153539fe1f8942ce3456297d5bf3115
BLAKE2b-256 checksum
How to use checksums
8f430a0796145646d79a61543d98fb83b0701eb89304d5c771fcd05be2481b8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page