Python setproctitle.getproctitle() Examples
The following are 17
code examples of setproctitle.getproctitle().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
setproctitle
, or try the search function
.
Example #1
Source File: test_advanced_3.py From ray with Apache License 2.0 | 6 votes |
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())
Example #2
Source File: worker.py From neutron-lib with Apache License 2.0 | 6 votes |
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()
Example #3
Source File: exceptions.py From ray with Apache License 2.0 | 6 votes |
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
Example #4
Source File: multiprocessing_executor.py From botoflow with Apache License 2.0 | 6 votes |
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
Example #5
Source File: rest_service.py From loopchain with Apache License 2.0 | 5 votes |
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.")
Example #6
Source File: job_engine.py From ibeis with Apache License 2.0 | 5 votes |
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')
Example #7
Source File: gunicorn_config.py From airflow with Apache License 2.0 | 5 votes |
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 )
Example #8
Source File: test_main.py From pgcli with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #9
Source File: common.py From certidude with MIT License | 5 votes |
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)
Example #10
Source File: __init__.py From pytest-salt with Apache License 2.0 | 5 votes |
def set_proc_title(title): if HAS_SETPROCTITLE is False: return setproctitle.setproctitle('[{}] - {}'.format(title, setproctitle.getproctitle()))
Example #11
Source File: test_utils.py From bigchaindb with Apache License 2.0 | 5 votes |
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
Example #12
Source File: test_utils.py From Decentralized-Internet with MIT License | 5 votes |
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
Example #13
Source File: test_consumer.py From yelp_kafka with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: consumer.py From yelp_kafka with Apache License 2.0 | 5 votes |
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)
Example #15
Source File: utils.py From allura with Apache License 2.0 | 5 votes |
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)
Example #16
Source File: taskd.py From allura with Apache License 2.0 | 5 votes |
def proctitle(title): """Temporarily change the process title, then restore it.""" orig_title = getproctitle() try: setproctitle(title) yield setproctitle(orig_title) except: setproctitle(orig_title) raise
Example #17
Source File: main.py From pgcli with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)