Skip to main content

Checks if a process (pid) is alive on Windows

Project description

Checks if a process (pid) is alive on Windows

pip install subprocess-alive

Tested against Windows 10 / Python 3.10 / Anaconda

from subprocess_alive import is_process_alive
import subprocess
from time import perf_counter
p = subprocess.Popen("ping 8.8.8.8", shell=True)

start = perf_counter()
while is_process_alive(p.pid):
    print(f"{p.pid} is alive", end="\r")
print(f"{p.pid} is not alive - execution time: {perf_counter()-start}")

start = perf_counter()
p = subprocess.Popen("ping 8.8.8.8", shell=False)
while is_process_alive(p.pid):
    print(f"{p.pid} is alive", end="\r")
print(f"{p.pid} is not alive - execution time: {perf_counter()-start}")



#output
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=9ms TTL=119
Reply from 8.8.8.8: bytes=32 time=11ms TTL=119
Reply from 8.8.8.8: bytes=32 time=9ms TTL=119
Reply from 8.8.8.8: bytes=32 time=10ms TTL=119
Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 9ms, Maximum = 11ms, Average = 9ms
18404 is not alive - execution time: 3.170662900000025
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=10ms TTL=119
Reply from 8.8.8.8: bytes=32 time=9ms TTL=119
Reply from 8.8.8.8: bytes=32 time=10ms TTL=119
Reply from 8.8.8.8: bytes=32 time=9ms TTL=119
Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 9ms, Maximum = 10ms, Average = 9ms
6788 is not alive - execution time: 3.1898495000023104

Project details


Download files

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

Source Distribution

subprocess_alive-0.10.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

subprocess_alive-0.10-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for subprocess_alive-0.10.tar.gz
Algorithm Hash digest
SHA256 80759f016f42d6b5db98278b29ef1f5b49070e5686160d6c963f797a398adf8d
MD5 d5ba3353ef231cdb5654157c139b3fbe
BLAKE2b-256 c28a60b11268319d885dd8b1706e6ad96757e8461d40afb94b75afd8824972a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subprocess_alive-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 3a485de4e1c8bcf424244d696b4152f7e466357c0f9a3903fdc76ff5a239726a
MD5 63df5b5f5e4d56c45d49a70854ac4ba1
BLAKE2b-256 0df0443739b598b1ff244235fe013f6e1631dc6fef9bd86a6d76dde8e8bd33bf

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