Debian Codegraph @

tests/execute/local_subprocess/bad_process.py

raw
1 """This is a non compliant process that does not listens to signals"""
2
3 # pragma: no cover
4 from __future__ import annotations
5
6 import os
7 import signal
8 import sys
9 import time
10 from pathlib import Path
11 from typing import TYPE_CHECKING
12
13 if TYPE_CHECKING:
14 from types import FrameType
15
16 out = sys.stdout
17
18
19 def handler(signum: int, _: FrameType | None) -> None:
20 _p(f"how about no signal {signum!r}")
21
22
23 def _p(m: str) -> None:
24 out.write(f"{m}{os.linesep}")
25 out.flush() # force output flush in case we get killed
26
27
28 _p(f"start {__name__} with {sys.argv!r}")
29 signal.signal(signal.SIGINT, handler)
30 signal.signal(signal.SIGTERM, handler)
31
32 try:
33 start_file = Path(sys.argv[1])
34 _p(f"create {start_file}")
35 start_file.write_text("", encoding="utf-8")
36 _p(f"created {start_file}")
37 while True:
38 time.sleep(0.01)
39 finally:
40 _p(f"done {__name__}")