From 690836d783193c76cd815b96e173b028574c3fce Mon Sep 17 00:00:00 2001 From: Sven Trenkel Date: Wed, 21 Apr 2010 18:26:55 +0200 Subject: [PATCH] python: Added documentation and an example on how to handle SIGCHLD. --- contrib/python/getsigchld.py | 21 +++++++++++++++++++++ src/collectd-python.pod | 9 +++++++++ 2 files changed, 30 insertions(+) create mode 100644 contrib/python/getsigchld.py diff --git a/contrib/python/getsigchld.py b/contrib/python/getsigchld.py new file mode 100644 index 00000000..557adc09 --- /dev/null +++ b/contrib/python/getsigchld.py @@ -0,0 +1,21 @@ +#!/usr/bin/python + +############################################################################### +# WARNING! Importing this script will break the exec plugin! # +############################################################################### +# Use this if you want to create new processes from your python scripts. # +# Normally you will get a OSError exception when the new process terminates # +# because collectd will ignore the SIGCHLD python is waiting for. # +# This script will restore the default SIGCHLD behavior so python scripts can # +# create new processes without errors. # +############################################################################### +# WARNING! Importing this script will break the exec plugin! # +############################################################################### + +import signal +import collectd + +def init(): + signal.signal(signal.SIGCHLD, signal.SIG_DFL) + +collectd.register_init(init) diff --git a/src/collectd-python.pod b/src/collectd-python.pod index 05a411cc..dd0f1f68 100644 --- a/src/collectd-python.pod +++ b/src/collectd-python.pod @@ -105,6 +105,15 @@ environment variable, e.g. I before starting collectd. Depending on your version of python this might or might not result in an B exception which can be ignored. +If you really need to spawn new processes from python you can register an init +callback and reset the action for SIGCHLD to the default behavior. Please note +that this I break the exec plugin. Do not even load the exec plugin if +you intend to do this! + +There is an example script located in B to do +this. If you import this from I SIGCHLD will be handled +normally and spawning processes from python will work as intended. + =back =item EB IE block -- 2.11.0