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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file gracefully_kill-0.10.tar.gz.

File metadata

  • Download URL: gracefully_kill-0.10.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for gracefully_kill-0.10.tar.gz
Algorithm Hash digest
SHA256 3f9aae40ebea46b0ca703b51990a0a5b5a7b8d30225ccf3cac3c127e148ec09e
MD5 7d69da6d3f4d02eea4d98171e7fcae19
BLAKE2b-256 3f743b71e16a164e442ce86e8f95c4eeb22b0d7573727851578d58b08df0d877

See more details on using hashes here.

File details

Details for the file gracefully_kill-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for gracefully_kill-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cde5bfc8ff6882374d208e63aeb79b05243f4108f0580dc8107d70b03c08a028
MD5 60c6451778440a2247e7d3b956512129
BLAKE2b-256 3230564f25d7a6a1dd801c1e60308dfb5d5b34111d5ad7153748f70b3fe362f7

See more details on using hashes here.

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