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