Skip to main content
https://img.shields.io/pypi/v/narration.svg https://img.shields.io/pypi/pyversions/narration.svg https://img.shields.io/pypi/status/narration.svg https://img.shields.io/pypi/l/narration.svg

narration

Logging is easy, but setup is messy and boring in multi processes contexts, due to the various way python can spawn processes (fork, spawn, forkserver) via explicit or implicit spawning context.

Narration handles the following logging setup boiler plate:

  • main process’s logger writes log record emitted by the process itself or its child processes

  • child process’s logger’s handler forward log records to the main process only

Installation

Install python virtual envs needed by tox/IDE

bash make.sh --setup-python-dev-envs
bash make.sh --install-dependencies
bash make.sh --install-tests-dependencies

Usage

  • Create your loggers as you like (eg: logging.basicConfig(…))

  • On the master process, setup the logger to act as server:

import narration
import multiprocessing
import logging

ctx = mutiprocessing.get_context()
m = ctx.Manager()

logger=logging.getLogger()
client_handler_settings = narration.setup_server_handlers(logger=logger, ctx=ctx, ctx_manager=m)
logger.debug("Main process ready")

pool = multiprocessing.pool.Pool(10, child_process_worker_function, [client_handler_settings] , 2, ctx)
  • On the child process, setup the logger to act as ‘emitting’ client:

import narration
import multiprocessing
import logging

# Child process must receive the 'client_handler_settings' payload when starting the process

# Re-create a logger, replacing handlers/formatting (if any) with handler to forrward records to the master process
logger=logging.getLogger()
narration.setup_client_handlers(logger=logger, handler_name_to_client_handler_settings=client_handler_settings)
logger.debug("Child process ready")
  • Child process log records will be sent to the master process’s logger’s original handlers for procesing.

Main process ready
Child process ready

Metadata

Release files for narration 0.2.21

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

Source distribution (sdist)

Source distribution for narration 0.2.21
File Size Uploaded
narration-0.2.21.tar.gz 30.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for narration 0.2.21
File Interpreter ABI Platform
narration-0.2.21-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 74.4 kB

Release files / narration-0.2.21.tar.gz

Download URL narration-0.2.21.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cfebff6157ddf1a405ec6f988143feb2541ff95049a991c22058f58611d37019
BLAKE2b-256 checksum
How to use checksums
2a0bbe097621d39921771c8f72816fb8ce70a3d36c6b33db74915805ce120d52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / narration-0.2.21-py2.py3-none-any.whl

Download URL narration-0.2.21-py2.py3-none-any.whl
Size 44.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cdff247d5f34556a6c70db886baa9c37473865d4971d4390b66808839394ae0f
BLAKE2b-256 checksum
How to use checksums
e95ef2df8e1cf5ae56c0ef3ba3536a6176f6109dd0691905aca5c4923742973f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.2.21 This release

2 release files

0.2.20

2 release files

0.2.19

2 release files

0.2.18

2 release files

0.2.13

1 release file

0.2.12

1 release file

0.2.10

1 release file

0.2.9

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

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