2020-08-05 10:43:35 +00:00
|
|
|
"""Test process util."""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.util import process
|
|
|
|
|
|
|
|
|
2023-02-07 09:26:56 +00:00
|
|
|
async def test_kill_process() -> None:
|
2020-08-05 10:43:35 +00:00
|
|
|
"""Test killing a process."""
|
|
|
|
sleeper = subprocess.Popen(
|
|
|
|
"sleep 1000",
|
|
|
|
shell=True, # nosec # shell by design
|
|
|
|
stdout=subprocess.DEVNULL,
|
|
|
|
stderr=subprocess.DEVNULL,
|
|
|
|
)
|
|
|
|
pid = sleeper.pid
|
|
|
|
|
|
|
|
assert os.kill(pid, 0) is None
|
|
|
|
|
|
|
|
process.kill_subprocess(sleeper)
|
|
|
|
|
|
|
|
with pytest.raises(OSError):
|
|
|
|
os.kill(pid, 0)
|