__init__.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Allow customization of the process title."""
  2. import os
  3. import sys
  4. import logging
  5. logger = logging.getLogger("setproctitle")
  6. __version__ = "1.3.5"
  7. __all__ = [
  8. "setproctitle",
  9. "getproctitle",
  10. "setthreadtitle",
  11. "getthreadtitle",
  12. ]
  13. def setproctitle(title: str) -> None:
  14. logger.debug("setproctitle C module not available")
  15. return None
  16. def getproctitle() -> str:
  17. logger.debug("setproctitle C module not available")
  18. return " ".join(sys.argv)
  19. def setthreadtitle(title: str) -> None:
  20. logger.debug("setproctitle C module not available")
  21. return None
  22. def getthreadtitle() -> str:
  23. logger.debug("setproctitle C module not available")
  24. return ""
  25. try:
  26. from . import _setproctitle # type: ignore
  27. except ImportError as e:
  28. # Emulate SPT_DEBUG showing process info in the C module.
  29. if os.environ.get("SPT_DEBUG", ""):
  30. logging.basicConfig()
  31. logger.setLevel(logging.DEBUG)
  32. logger.debug("failed to import setproctitle: %s", e)
  33. else:
  34. setproctitle = _setproctitle.setproctitle # noqa: F811
  35. getproctitle = _setproctitle.getproctitle # noqa: F811
  36. setthreadtitle = _setproctitle.setthreadtitle # noqa: F811
  37. getthreadtitle = _setproctitle.getthreadtitle # noqa: F811
  38. # Call getproctitle to initialize structures and avoid problems caused
  39. # by fork() on macOS (see #113).
  40. if sys.platform == "darwin":
  41. getproctitle()