Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[All Platforms] Improve documentation examples for cascaded processes #1855

Closed
dinuta opened this issue Oct 19, 2020 · 1 comment
Closed

Comments

@dinuta
Copy link

dinuta commented Oct 19, 2020

Consider this example slightly modified from your documentation:

import os
import signal
import psutil

def kill_proc_tree(sig=signal.SIGTERM, include_parent=False,
                   timeout=None, on_terminate=None):
    """Kill a process tree (including grandchildren) with signal
    "sig" and return a (gone, still_alive) tuple.
    "on_terminate", if specified, is a callabck function which is
    called as soon as a child terminates.
    """
    parent = psutil.Process(os.getpid())
    children = parent.children(recursive=True)
    if include_parent:
        children.append(parent)
    for p in children:
        p.send_signal(sig)
    gone, alive = psutil.wait_procs(children, timeout=timeout,
                                    callback=on_terminate)
    return (gone, alive)
  1. os.getpid() is the Flask microservice
  2. The service parent process opens childs using another python script in detached mode with p = subprocess.Popen(PYTHON_SCRIPT, env=CmdUtils.__env.get_env_and_virtual_env())
  3. The PYTHON_SCRIPT is running system commands with variable run times (from milliseconds to minutes/hour...).

The problem is that the above piece of code will raise an error for the processes that were closed very fast.

Please revisit the examples and documentation.

@giampaolo
Copy link
Owner

Good catch.

@giampaolo giampaolo added the doc label Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants