File: __init__.py

package info (click to toggle)
python-setproctitle 1.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: ansic: 946; python: 659; makefile: 21
file content (57 lines) | stat: -rw-r--r-- 1,409 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Allow customization of the process title."""

import os
import sys
import logging

logger = logging.getLogger("setproctitle")

__version__ = "1.3.7"

__all__ = [
    "setproctitle",
    "getproctitle",
    "setthreadtitle",
    "getthreadtitle",
]


def setproctitle(title: str) -> None:
    logger.debug("setproctitle C module not available")
    return None


def getproctitle() -> str:
    logger.debug("setproctitle C module not available")
    return " ".join(sys.argv)


def setthreadtitle(title: str) -> None:
    logger.debug("setproctitle C module not available")
    return None


def getthreadtitle() -> str:
    logger.debug("setproctitle C module not available")
    return ""


try:
    from . import _setproctitle  # type: ignore
except ImportError as e:
    # Emulate SPT_DEBUG showing process info in the C module.
    if os.environ.get("SPT_DEBUG", ""):
        logging.basicConfig()
        logger.setLevel(logging.DEBUG)
    logger.debug("failed to import setproctitle: %s", e)
else:
    setproctitle = _setproctitle.setproctitle  # noqa: F811
    getproctitle = _setproctitle.getproctitle  # noqa: F811
    setthreadtitle = _setproctitle.setthreadtitle  # noqa: F811
    getthreadtitle = _setproctitle.getthreadtitle  # noqa: F811


# Call getproctitle to initialize structures and avoid problems caused
# by fork() on macOS (see #113).
if sys.platform == "darwin":
    getproctitle()