Spaces:
Running
on
Zero
Running
on
Zero
File size: 931 Bytes
d1ed09d |
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 |
from __future__ import annotations
import os
try:
import setproctitle as setproctitle_mod
except ImportError:
setproctitle_mod = None
_enabled = False
def enable_proctitle_on_children():
"""
Enable setting the process title on this process' children and
grandchildren.
"""
os.environ["DASK_PARENT"] = str(os.getpid())
def enable_proctitle_on_current():
"""
Enable setting the process title on this process.
"""
global _enabled
_enabled = True
def setproctitle(title):
"""
Change this process' title, as displayed in various utilities
such as `ps`.
"""
if setproctitle_mod is None:
return
enabled = _enabled
if not enabled:
try:
enabled = int(os.environ.get("DASK_PARENT", "")) != os.getpid()
except ValueError: # pragma: no cover
pass
if enabled:
setproctitle_mod.setproctitle(title)
|