本文整理匯總了Python中setproctitle.getproctitle方法的典型用法代碼示例。如果您正苦於以下問題:Python setproctitle.getproctitle方法的具體用法?Python setproctitle.getproctitle怎麽用?Python setproctitle.getproctitle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類setproctitle
的用法示例。
在下文中一共展示了setproctitle.getproctitle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: drop_privileges
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def drop_privileges():
from certidude import config
import pwd
_, _, uid, gid, gecos, root, shell = pwd.getpwnam("certidude")
restricted_groups = []
restricted_groups.append(gid)
# PAM needs access to /etc/shadow
if config.AUTHENTICATION_BACKENDS == {"pam"}:
import grp
name, passwd, num, mem = grp.getgrnam("shadow")
click.echo("Adding current user to shadow group due to PAM authentication backend")
restricted_groups.append(num)
os.setgroups(restricted_groups)
os.setgid(gid)
os.setuid(uid)
click.echo("Switched %s (pid=%d) to user %s (uid=%d, gid=%d); member of groups %s" %
(getproctitle(), os.getpid(), "certidude", os.getuid(), os.getgid(), ", ".join([str(j) for j in os.getgroups()])))
os.umask(0o007)
示例2: initializer
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def initializer(self):
"""If set, the initializer function will be called after the subprocess
is started with the worker object as the first argument.
You can use this to, for example, set the process name suffix, to
distinguish between activity and workflow workers (when starting them
from the same process):
.. code-block:: python
from setproctitle import getproctitle, setproctitle
def set_worker_title(worker):
name = getproctitle()
if isinstance(worker, WorkflowWorker):
setproctitle(name + ' (WorkflowWorker)')
elif isinstance(worker, ActivityWorker):
setproctitle(name + ' (ActivityWorker)')
worker.initializer = set_worker_title
"""
try:
return self.__initializer
except AttributeError:
return lambda obj: None
示例3: __init__
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def __init__(self,
function_name,
traceback_str,
cause_cls,
proctitle=None,
pid=None,
ip=None):
"""Initialize a RayTaskError."""
if proctitle:
self.proctitle = proctitle
else:
self.proctitle = setproctitle.getproctitle()
self.pid = pid or os.getpid()
self.ip = ip or ray.services.get_node_ip_address()
self.function_name = function_name
self.traceback_str = traceback_str
self.cause_cls = cause_cls
assert traceback_str is not None
示例4: test_ray_setproctitle
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def test_ray_setproctitle(ray_start_2_cpus):
@ray.remote
class UniqueName:
def __init__(self):
assert setproctitle.getproctitle() == "ray::UniqueName.__init__()"
def f(self):
assert setproctitle.getproctitle() == "ray::UniqueName.f()"
@ray.remote
def unique_1():
assert "unique_1" in setproctitle.getproctitle()
actor = UniqueName.remote()
ray.get(actor.f.remote())
ray.get(unique_1.remote())
示例5: __init__
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def __init__(self, worker_process_count=_default_process_count,
set_proctitle='on'):
"""Initialize a worker instance.
:param worker_process_count: Defines how many processes to spawn for
worker:
0 - spawn 1 new worker thread,
1..N - spawn N new worker processes
set_proctitle:
'off' - do not change process title
'on' - set process title to descriptive string and parent
'brief' - set process title to descriptive string
"""
self._worker_process_count = worker_process_count
self._my_pid = os.getpid()
self._set_proctitle = set_proctitle
if set_proctitle == 'on':
self._parent_proctitle = setproctitle.getproctitle()
示例6: obfuscate_process_password
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def obfuscate_process_password():
process_title = setproctitle.getproctitle()
if "://" in process_title:
process_title = re.sub(r":(.*):(.*)@", r":\1:xxxx@", process_title)
elif "=" in process_title:
process_title = re.sub(
r"password=(.+?)((\s[a-zA-Z]+=)|$)", r"password=xxxx\2", process_title
)
setproctitle.setproctitle(process_title)
示例7: test_obfuscate_process_password
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def test_obfuscate_process_password():
original_title = setproctitle.getproctitle()
setproctitle.setproctitle("pgcli user=root password=secret host=localhost")
obfuscate_process_password()
title = setproctitle.getproctitle()
expected = "pgcli user=root password=xxxx host=localhost"
assert title == expected
setproctitle.setproctitle("pgcli user=root password=top secret host=localhost")
obfuscate_process_password()
title = setproctitle.getproctitle()
expected = "pgcli user=root password=xxxx host=localhost"
assert title == expected
setproctitle.setproctitle("pgcli user=root password=top secret")
obfuscate_process_password()
title = setproctitle.getproctitle()
expected = "pgcli user=root password=xxxx"
assert title == expected
setproctitle.setproctitle("pgcli postgres://root:secret@localhost/db")
obfuscate_process_password()
title = setproctitle.getproctitle()
expected = "pgcli postgres://root:xxxx@localhost/db"
assert title == expected
setproctitle.setproctitle(original_title)
示例8: run
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def run(self, conn, event: multiprocessing.Event):
logging.debug("RestService run...")
args = ['python3', '-m', 'loopchain', 'rest', '-p', str(self._port)]
args += command_arguments.get_raw_commands_by_filter(
command_arguments.Type.AMQPKey,
command_arguments.Type.RadioStationTarget
)
server = CommonSubprocess(args)
api_port = self._port + conf.PORT_DIFF_REST_SERVICE_CONTAINER
server.set_proctitle(f"{setproctitle.getproctitle()} RestServer api_port({api_port})")
logging.info(f'RestService run complete port {self._port}')
# complete init
event.set()
command = None
while command != "quit":
try:
command, param = conn.recv()
logging.debug(f"RestService got: {param}")
except Exception as e:
logging.warning(f"RestService conn.recv() error: {e}")
except KeyboardInterrupt:
pass
server.stop()
logging.info("RestService Ended.")
示例9: update_proctitle
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def update_proctitle(procname):
try:
import setproctitle
print('CHANGING PROCESS TITLE')
old_title = setproctitle.getproctitle()
print('old_title = %r' % (old_title,))
#new_title = 'IBEIS_' + procname + ' ' + old_title
#new_title = procname + ' ' + old_title
new_title = 'ibeis_zmq_loop'
print('new_title = %r' % (new_title,))
setproctitle.setproctitle(new_title)
except ImportError:
print('pip install setproctitle')
示例10: post_worker_init
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def post_worker_init(_):
"""
Set process title.
This is used by airflow.cli.commands.webserver_command to track the status of the worker.
"""
old_title = setproctitle.getproctitle() # pylint: disable=c-extension-no-member
setproctitle.setproctitle( # pylint: disable=c-extension-no-member
settings.GUNICORN_WORKER_READY_PREFIX + old_title
)
示例11: set_proc_title
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def set_proc_title(title):
if HAS_SETPROCTITLE is False:
return
setproctitle.setproctitle('[{}] - {}'.format(title, setproctitle.getproctitle()))
示例12: test_process_set_title
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def test_process_set_title():
from uuid import uuid4
from multiprocessing import Queue
from setproctitle import getproctitle
from bigchaindb.utils import Process
queue = Queue()
uuid = str(uuid4())
process = Process(target=lambda: queue.put(getproctitle()),
name=uuid)
process.start()
assert queue.get() == uuid
示例13: test_set_process_name
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def test_set_process_name(self, config):
consumer = KafkaConsumerBase(
'my_very_extraordinarily_elongated_topic_name',
config, ['1', '2', '3', '4', '5'])
with mock.patch(
'yelp_kafka.consumer.setproctitle',
) as mock_setproctitle:
consumer.set_process_name()
expected_name = \
'{procname}-my_very_extraordinarily_elongated_topic_name' \
'-{messages}'.format(
procname=getproctitle(),
messages=['1', '2', '3', '4', '5'],
)
mock_setproctitle.assert_called_with(expected_name)
示例14: set_process_name
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def set_process_name(self):
"""Setup process name for consumer to include topic and
partitions to improve debuggability.
"""
process_name = '%s-%s-%s' % (getproctitle(), self.topic.decode(), self.partitions)
setproctitle(process_name)
示例15: format
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import getproctitle [as 別名]
def format(self, record):
"""Prepends current process name to ``record.name`` if running in the
context of a taskd process that is currently processing a task.
"""
title = getproctitle()
if title.startswith(b'taskd:'):
record.name = "{0}:{1}".format(title, record.name)
return super(CustomWatchedFileHandler, self).format(record)