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
Release history Release notifications | RSS feed
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 hashes)
Built Distribution
Close
Hashes for subprocess_alive-0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a485de4e1c8bcf424244d696b4152f7e466357c0f9a3903fdc76ff5a239726a |
|
MD5 | 63df5b5f5e4d56c45d49a70854ac4ba1 |
|
BLAKE2b-256 | 0df0443739b598b1ff244235fe013f6e1631dc6fef9bd86a6d76dde8e8bd33bf |