Skip to main content

Terminates a subprocess gracefully, if it doesn't work, it will be killed (Windows only)

Project description

Terminates a subprocess gracefully, if it doesn't work, it will be killed (Windows only)

pip install gracefully_kill

Tested against Windows 10 / Python 3.10 / Anaconda

The function attempts to terminate the subprocess gracefully by closing its standard input, output, and error streams, waiting for a specified timeout, and finally terminating the process. This allows the subprocess to clean up its resources and exit properly. The function checks if the process is still alive after termination attempts. If it is, it uses the taskkill_force_pid_children function from the taskkill module to forcibly terminate any child processes associated with the given process ID. This ensures that the entire process hierarchy is terminated if necessary.

pro=subprocess.Popen('ping -t 8.8.8.8')
kill_process(pro, timeout=1)

Project details


Release history Release notifications | RSS feed

This version

0.10

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gracefully_kill-0.10.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

gracefully_kill-0.10-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page