{"id":10370,"library":"zope-processlifetime","title":"Zope Process Lifetime","description":"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.","status":"active","version":"4.0","language":"python","source_language":"en","source_url":"https://github.com/zopefoundation/zope.processlifetime","tags":["zope","lifecycle","events","process","toolkit","framework"],"install":[{"cmd":"pip install zope.processlifetime","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Provides the event interfaces and mechanisms for event registration and dispatch required by zope.processlifetime.","package":"zope.interface","optional":false}],"imports":[{"wrong":"from zope.processlifetime import registerProcessSubscriber","symbol":"registerProcessSubscriber","correct":"from zope.processlifetime import registerProcessSubscriber"}],"quickstart":{"code":"import os\nfrom zope.processlifetime import registerProcessSubscriber, IProcessStarting, IProcessInitialized, IProcessStopping\nfrom zope.interface import implementer\nimport zope.event # Required for dispatching events\n\n# Define handler functions that will react to events\ndef handle_startup(event):\n    print(\"Process starting event received!\")\n    # Typically, you would initialize resources here\n    assert isinstance(event, IProcessStarting)\n\ndef handle_initialized(event):\n    print(\"Process initialized event received!\")\n    # Typically, you would confirm readiness or start background tasks here\n    assert isinstance(event, IProcessInitialized)\n\ndef handle_stopping(event):\n    print(\"Process stopping event received!\")\n    # Typically, you would clean up resources or save state here\n    assert isinstance(event, IProcessStopping)\n\n# Register the handler functions for the respective lifecycle interfaces\nregisterProcessSubscriber(handle_startup, IProcessStarting)\nregisterProcessSubscriber(handle_initialized, IProcessInitialized)\nregisterProcessSubscriber(handle_stopping, IProcessStopping)\n\nprint(\"Subscribers registered. Now simulating event dispatch:\")\n\n# In a real Zope application, a framework or server would dispatch these events.\n# For demonstration, we create and notify them explicitly using zope.event.\n\n# Define simple event objects that implement the interfaces\n@implementer(IProcessStarting)\nclass ProcessStartingEvent: pass\n\n@implementer(IProcessInitialized)\nclass ProcessInitializedEvent: pass\n\n@implementer(IProcessStopping)\nclass ProcessStoppingEvent: pass\n\n# Dispatch the events to trigger the registered handlers\nzope.event.notify(ProcessStartingEvent())\nzope.event.notify(ProcessInitializedEvent())\nzope.event.notify(ProcessStoppingEvent())\n\nprint(\"\\nEvents dispatched. Check console output for handler messages.\")\n# Note: os.environ.get('AUTH_KEY', '') is not relevant for this library's quickstart.","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your project's Python interpreter is version 3.9 or newer. Upgrade your Python environment if necessary.","message":"Version 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.","severity":"breaking","affected_versions":"4.0+"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"It'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`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"search_vec":"'4.0':49 'api':7 'applic':44 'base':43 'cleanup':39 'compon':29 'core':28 'current':46 'enabl':34 'event':12,64 'follow':53 'foundat':60 'framework':67 'initi':22,61 'lifecycl':18,63 'lifetim':3 'major':54 'manag':37 'occur':13 'process':2,16,65 'provid':5 'python':55 'regist':9 'releas':51 'resourc':36 'robust':35 'start':21 'stop':24 'subscrib':10 'toolkit':33,66 'typic':52 'updat':57 'version':47,56 'zope':1,32,42,59,62 'zope-bas':41 'zope.processlifetime':4","created_at":"2026-04-17T01:23:46.819643+00:00","updated_at":"2026-04-17T01:23:46.819643+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nImportError: cannot import name 'registerProcessSubscriber' from 'zope.processlifetime' (/tmp/tmplfz_ddfx/venv/lib/python3.12/site-packages/zope/processlifetime/__init__.py)"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"http://github.com/zopefoundation/zope.processlifetime","docs":null,"changelog":null,"pypi":"https://pypi.org/project/zope-processlifetime/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}