# Checks if a process (pid) is alive on Windows
### pip install subprocess-alive
#### Tested against Windows 10 / Python 3.10 / Anaconda
```python
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/subprocess_alive",
"name": "subprocess-alive",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pid,isalive",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c2/8a/60b11268319d885dd8b1706e6ad96757e8461d40afb94b75afd8824972a5/subprocess_alive-0.10.tar.gz",
"platform": null,
"description": "# Checks if a process (pid) is alive on Windows \r\n\r\n### pip install subprocess-alive\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda\r\n\r\n\r\n```python\r\n\r\nfrom subprocess_alive import is_process_alive\r\nimport subprocess\r\nfrom time import perf_counter\r\np = subprocess.Popen(\"ping 8.8.8.8\", shell=True)\r\n\r\nstart = perf_counter()\r\nwhile is_process_alive(p.pid):\r\n print(f\"{p.pid} is alive\", end=\"\\r\")\r\nprint(f\"{p.pid} is not alive - execution time: {perf_counter()-start}\")\r\n\r\nstart = perf_counter()\r\np = subprocess.Popen(\"ping 8.8.8.8\", shell=False)\r\nwhile is_process_alive(p.pid):\r\n print(f\"{p.pid} is alive\", end=\"\\r\")\r\nprint(f\"{p.pid} is not alive - execution time: {perf_counter()-start}\")\r\n\r\n\r\n\r\n#output\r\nPinging 8.8.8.8 with 32 bytes of data:\r\nReply from 8.8.8.8: bytes=32 time=9ms TTL=119\r\nReply from 8.8.8.8: bytes=32 time=11ms TTL=119\r\nReply from 8.8.8.8: bytes=32 time=9ms TTL=119\r\nReply from 8.8.8.8: bytes=32 time=10ms TTL=119\r\nPing statistics for 8.8.8.8:\r\n Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n Minimum = 9ms, Maximum = 11ms, Average = 9ms\r\n18404 is not alive - execution time: 3.170662900000025\r\nPinging 8.8.8.8 with 32 bytes of data:\r\nReply from 8.8.8.8: bytes=32 time=10ms TTL=119\r\nReply from 8.8.8.8: bytes=32 time=9ms TTL=119\r\nReply from 8.8.8.8: bytes=32 time=10ms TTL=119\r\nReply from 8.8.8.8: bytes=32 time=9ms TTL=119\r\nPing statistics for 8.8.8.8:\r\n Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n Minimum = 9ms, Maximum = 10ms, Average = 9ms\r\n6788 is not alive - execution time: 3.1898495000023104\r\n\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Checks if a process (pid) is alive on Windows",
"version": "0.10",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/subprocess_alive"
},
"split_keywords": [
"pid",
"isalive"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0df0443739b598b1ff244235fe013f6e1631dc6fef9bd86a6d76dde8e8bd33bf",
"md5": "63df5b5f5e4d56c45d49a70854ac4ba1",
"sha256": "3a485de4e1c8bcf424244d696b4152f7e466357c0f9a3903fdc76ff5a239726a"
},
"downloads": -1,
"filename": "subprocess_alive-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "63df5b5f5e4d56c45d49a70854ac4ba1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5802,
"upload_time": "2023-04-15T03:24:26",
"upload_time_iso_8601": "2023-04-15T03:24:26.194445Z",
"url": "https://files.pythonhosted.org/packages/0d/f0/443739b598b1ff244235fe013f6e1631dc6fef9bd86a6d76dde8e8bd33bf/subprocess_alive-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c28a60b11268319d885dd8b1706e6ad96757e8461d40afb94b75afd8824972a5",
"md5": "d5ba3353ef231cdb5654157c139b3fbe",
"sha256": "80759f016f42d6b5db98278b29ef1f5b49070e5686160d6c963f797a398adf8d"
},
"downloads": -1,
"filename": "subprocess_alive-0.10.tar.gz",
"has_sig": false,
"md5_digest": "d5ba3353ef231cdb5654157c139b3fbe",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3595,
"upload_time": "2023-04-15T03:24:28",
"upload_time_iso_8601": "2023-04-15T03:24:28.740763Z",
"url": "https://files.pythonhosted.org/packages/c2/8a/60b11268319d885dd8b1706e6ad96757e8461d40afb94b75afd8824972a5/subprocess_alive-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-15 03:24:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "subprocess_alive",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "subprocess-alive"
}