summaryrefslogtreecommitdiff
path: root/tests/execute/local_subprocess/bad_process.py
blob: 4870d058334d37d190d62f56cc3f2c61b943a1fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""This is a non compliant process that does not listens to signals"""
# pragma: no cover
from __future__ import annotations

import os
import signal
import sys
import time
from pathlib import Path
from types import FrameType

out = sys.stdout


def handler(signum: int, _: FrameType | None) -> None:  # noqa: U101
    _p(f"how about no signal {signum!r}")


def _p(m: str) -> None:
    out.write(f"{m}{os.linesep}")
    out.flush()  # force output flush in case we get killed


_p(f"start {__name__} with {sys.argv!r}")
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)

try:
    start_file = Path(sys.argv[1])
    _p(f"create {start_file}")
    start_file.write_text("")
    _p(f"created {start_file}")
    while True:
        time.sleep(0.01)
finally:
    _p(f"done {__name__}")