Skip to main content

Drekar Launch Process

This library contains client utility functions for processes launched using drekar-launch, although they may also be used without drekar-launch. Currently this package provides a reliable way for processes to receive shutdown signals from a process manager or the user using ctrl-c.

See drekar-launch: https://github.com/johnwason/drekar-launch

Installation

python -m pip install --user drekar-launch-process

On Ubuntu, it may be necessary to replace python with python3.

Usage

The module contains three functions:

  • drekar_launch_process.wait_exit() - Block and wait for exit
  • drekar_launch_process.wait_exit_callback(callback) - Return immediately and call callback() when shutdown signal received
  • drekar_launch_process.wait_exit_stop_loop(loop) - Call to stop an asyncio loop when shutdown signal received

Example

A simple example of running a Python http server in a background thread, using the blocking wait_exit().

import drekar_launch_process
import threading
from http import server as http_server

server=http_server.ThreadingHTTPServer(('',8085), 
        http_server.SimpleHTTPRequestHandler)
def run_server():
    server.serve_forever()

th = threading.Thread(target=run_server)
th.daemon = True
th.start()

drekar_launch_process.wait_exit()

This example uses the callback version to quit the http server:

import drekar_launch_process
import threading
from http import server as http_server

server=http_server.ThreadingHTTPServer(('',8085), 
        http_server.SimpleHTTPRequestHandler)

def shutdown_server():
    server.shutdown()

drekar_launch_process.wait_exit_callback(shutdown_server)

server.serve_forever()

Shutdown Signal Explanation

Reliably sending a shutdown/quit command to a process in a cross-platform manner is surprisingly difficult. On POSIX based systems like Linux and Mac OS X, signals such as SIGINT or SIGTERM are typically sent. (Ctrl-C sends SIGINT). These signals can be caught by the process, and used to gracefully shut down. SIGKILL is used to immediately terminate the process.

On Windows, it is significantly more difficult. Windows typically uses "Window Message Queues" to communicate with processes. Even processes like services that do not have a visible window often have a hidden window so messages can be received from the operating system. There is some functionality for sending console signals, but these are not reliable for all cases. Windows also has the concept of Job Objects that can be used to group different processes together. The combination of job objects and windows messages provide a reliable way to send and receive graceful shutdown signals.

The wait_for_exit* commands either way for Signals on POSIX, or windows close messages and console events on Windows.

Metadata

Release files for drekar-launch-process 0.1.3

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

Built distribution (wheel)

Table of built distributions (wheels) for drekar-launch-process 0.1.3
File Interpreter ABI Platform
drekar_launch_process-0.1.3-py3-none-any.whl Python 3 none any Details

Release files / drekar_launch_process-0.1.3-py3-none-any.whl

Download URL drekar_launch_process-0.1.3-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0df899edc0dc46b705b25a071ea5181a94c4e56a9d27ec2f0a7646e176c5bd8
BLAKE2b-256 checksum
How to use checksums
e3cdcec8cc1eaa3c3272c9d90f93ec4ff8882d3e420fce0d655e78857ef75439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.3 This release

1 release file

0.1.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