File: bad_process.py

package info (click to toggle)
tox 4.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,096 kB
  • sloc: python: 19,473; sh: 22; makefile: 14
file content (40 lines) | stat: -rw-r--r-- 870 bytes parent folder | download
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
37
38
39
40
"""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 typing import TYPE_CHECKING

if TYPE_CHECKING:
    from types import FrameType

out = sys.stdout


def handler(signum: int, _: FrameType | None) -> None:
    _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("", encoding="utf-8")
    _p(f"created {start_file}")
    while True:
        time.sleep(0.01)
finally:
    _p(f"done {__name__}")