Registry / web-framework / zope-processlifetime

zope-processlifetime

JSON →
library4.0pypypiunverified

zope.processlifetime provides an API for registering subscribers to events occurring during a process's lifecycle, such as starting, initialized, and stopping. It is a core component of the Zope Toolkit, enabling robust resource management and cleanup in Zope-based applications. The current version is 4.0, with releases typically following major Python version updates or Zope Foundation initiatives.

pip install zope.processlifetime
INSTALL
IMPORT
SIG · ZOPE-PROCESSLIFETI
Z
zope-processlifetime
web-frameworkpythonv4.0
Install
2.1s avg
Import
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.1s · import 0.000s · 20MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

registerProcessSubscriber
from zope.processlifetime import registerProcessSubscriber
from zope.processlifetime import registerProcessSubscriber

This quickstart demonstrates how to define handler functions and register them with `zope.processlifetime.registerProcessSubscriber` for specific process lifecycle events. It also shows how to explicitly dispatch these events using `zope.event.notify` for testing purposes, which is typically handled automatically by a Zope application server in a production environment.

import os from zope.processlifetime import registerProcessSubscriber, IProcessStarting, IProcessInitialized, IProcessStopping from zope.interface import implementer import zope.event # Required for dispatching events # Define handler functions that will react to events def handle_startup(event): print("Process starting event received!") # Typically, you would initialize resources here assert isinstance(event, IProcessStarting) def handle_initialized(event): print("Process initialized event received!") # Typically, you would confirm readiness or start background tasks here assert isinstance(event, IProcessInitialized) def handle_stopping(event): print("Process stopping event received!") # Typically, you would clean up resources or save state here assert isinstance(event, IProcessStopping) # Register the handler functions for the respective lifecycle interfaces registerProcessSubscriber(handle_startup, IProcessStarting) registerProcessSubscriber(handle_initialized, IProcessInitialized) registerProcessSubscriber(handle_stopping, IProcessStopping) print("Subscribers registered. Now simulating event dispatch:") # In a real Zope application, a framework or server would dispatch these events. # For demonstration, we create and notify them explicitly using zope.event. # Define simple event objects that implement the interfaces @implementer(IProcessStarting) class ProcessStartingEvent: pass @implementer(IProcessInitialized) class ProcessInitializedEvent: pass @implementer(IProcessStopping) class ProcessStoppingEvent: pass # Dispatch the events to trigger the registered handlers zope.event.notify(ProcessStartingEvent()) zope.event.notify(ProcessInitializedEvent()) zope.event.notify(ProcessStoppingEvent()) print("\nEvents dispatched. Check console output for handler messages.") # Note: os.environ.get('AUTH_KEY', '') is not relevant for this library's quickstart.
Debug
Known issues
breakingVersion 4.0+ of `zope.processlifetime` requires Python 3.9 or higher. Older versions (e.g., 3.x) supported Python 2.7 and Python 3.5-3.8. Upgrading from older Python versions or older `zope.processlifetime` versions will require updating your Python environment.
fix
Ensure your project's Python interpreter is version 3.9 or newer. Upgrade your Python environment if necessary.
affects: 4.0+
gotchaThe events (e.g., `IProcessStarting`) are *not* automatically dispatched by `zope.processlifetime` itself. This library only provides the registration mechanism. Event dispatch is typically handled by a higher-level Zope-based framework or application server (like Zope or Plone) using `zope.event.notify()` at appropriate stages of its lifecycle.
fix
When testing or developing outside a full Zope environment, you must explicitly create event objects (implementing the respective `IProcess*` interfaces) and dispatch them using `zope.event.notify(your_event_object)` to trigger your subscribers.
affects: All
gotchaIt's easy to confuse the process lifetime events with other event systems or directly calling handler functions. Ensure you are registering your handler with the correct `IProcess*` interface from `zope.processlifetime`.
fix
Always import the specific event interfaces (e.g., `IProcessStarting`) from `zope.processlifetime` and pass them as the second argument to `registerProcessSubscriber`. Your handler function will receive an object that implements that interface.
affects: All
Upgrade
Version history
4.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredProvides the event interfaces and mechanisms for event registration and dispatch required by zope.processlifetime.
Agent activity
38 hits · last 30 days
node
32
Amazon
1
OpenAI (training)
1
Resources
zope-processlifetime — pip install zope-processlifetime · libregistry