本文整理匯總了Python中setproctitle.setproctitle方法的典型用法代碼示例。如果您正苦於以下問題:Python setproctitle.setproctitle方法的具體用法?Python setproctitle.setproctitle怎麽用?Python setproctitle.setproctitle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類setproctitle
的用法示例。
在下文中一共展示了setproctitle.setproctitle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def run(self):
self.allow_reuse_address = True
self.daemon_threads = True
try:
SocketServer.TCPServer.__init__(
self, (self.ip or '', self.port), StreamRequestHandler)
except socket.error:
logger.critical(
'The streaming server could not bind to your specified port '
'({port}). Perhaps this is already in use? The application '
'cannot work properly!'.format(port=self.port))
sys.exit(1)
signal.signal(signal.SIGTERM, self.shutdown)
if self.proc_title:
setproctitle.setproctitle(self.proc_title)
self.serve_forever()
示例2: __init__
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def __init__(self):
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
setproctitle.setproctitle('pulseaudio-daemon')
self.mainloop = GObject.MainLoop()
self.processes = []
self.check_id = None
self.is_checking = False
self._check_processes()
signals = (
('NameOwnerChanged', 'org.freedesktop.DBus.{}',
self.on_name_owner_changed),
)
self.bus = dbus.SystemBus()
self.core = self.bus.get_object('org.freedesktop.DBus', '/')
for sig_name, interface, sig_handler in signals:
self.bus.add_signal_receiver(sig_handler, sig_name)
示例3: run
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def run(self, ttl=None):
if self.DISABLE_SSDP_LISTENER:
return
self.allow_reuse_address = True
SocketServer.UDPServer.__init__(
self, (self.host or '', self.SSDP_PORT), SSDPHandler)
self.socket.setsockopt(
socket.IPPROTO_IP,
socket.IP_ADD_MEMBERSHIP,
self._multicast_struct(self.SSDP_ADDRESS))
self.socket.setsockopt(
socket.IPPROTO_IP,
socket.IP_MULTICAST_TTL,
self.SSDP_TTL)
if ttl:
GObject.timeout_add(ttl * 1000, self.shutdown)
setproctitle.setproctitle('ssdp_listener')
self.serve_forever(self)
logger.info('SSDPListener.run()')
示例4: _process_wrapper
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def _process_wrapper(exit_event, proc_name, function, agent_name=None):
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGHUP, _mutate_config)
if agent_name:
process_title = 'octavia-driver-agent - {} -- {}'.format(
proc_name, agent_name)
else:
process_title = 'octavia-driver-agent - {}'.format(proc_name)
setproctitle.setproctitle(process_title)
while not exit_event.is_set():
try:
function(exit_event)
except Exception as e:
if agent_name:
LOG.exception('Provider agent "%s" raised exception: %s. '
'Restarting the "%s" provider agent.',
agent_name, str(e), agent_name)
else:
LOG.exception('%s raised exception: %s. '
'Restarting %s.',
proc_name, str(e), proc_name)
time.sleep(1)
continue
break
示例5: try_set_process_name
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def try_set_process_name(self, name=None):
"""This helper method may be used to try to change a process's name
in order to make discriminating which role a particular process is
fulfilling. This uses a third-party utility library that may not behave
the same way on all platforms, and therefore this is done for convenience
only.
Parameters
----------
name : str, optional
A name to set. If not provided, will check the attribute ``process_name``
for a non-null value, or else have no effect.
"""
if name is None:
name = getattr(self, 'process_name', None)
if name is None:
return
try:
import setproctitle
setproctitle.setproctitle(name)
except (ImportError, AttributeError):
pass
示例6: predict_one
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def predict_one(self, data=None):
# TODO(reduce data in limited batch)
assert len(self.summary_dict) == 0, "still not support scalar summary in testing stage"
setproctitle.setproctitle('test ' + self.cfg.proj_name + ' epoch:' + str(self.cur_epoch))
self.read_timer.tic()
feed_dict, batch_size = self.next_feed(data)
self.read_timer.toc()
self.timer.tic()
res = self.sess.run([*self.graph_ops, *self.summary_dict.values()], feed_dict=feed_dict)
self.timer.toc()
if data is not None and len(data[0]) < self.cfg.nr_gpus * batch_size:
for i in range(len(res)):
res[i] = res[i][:len(data[0])]
return res
示例7: set_process_title
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def set_process_title(arg=None):
'''
Decorator for setting the process title
Can be applied in two ways:
@set_process_title
@set_process_title('new_process_title')
Defaults to 'fossor'
'''
title = 'fossor'
if type(arg) == str:
title = arg
def real_decorator(function):
@wraps(function)
def wrapper(*args, **kwargs):
setproctitle.setproctitle(title + ' ' + ' '.join(sys.argv[1:]))
function(*args, **kwargs)
return wrapper
# If called as @set_process_title
if callable(arg):
return real_decorator(arg)
# If called as @set_process_title('new_title')
return real_decorator
示例8: _setup
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def _setup(self):
"""
Set actor specific configuration:
- set the processus name
- setup the socket interface
- setup the signal handler
This method is called before entering on the behaviour loop
"""
# Name process
setproctitle.setproctitle(self.name)
self.socket_interface.setup()
self.logger.debug(self.name + ' process created.')
self._signal_handler_setup()
self.setup()
示例9: main
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def main():
# get the parameters
parser = argparse.ArgumentParser(description="PyTorch Segmentation Model Training")
args = parser_params.add_parser_params(parser)
print(args)
parser_params.save_hp_to_json(args)
# set the name of the process
setproctitle.setproctitle(args.proc_name)
torch.manual_seed(args.seed)
trainer = Trainer(args)
print('INFO:PyTorch: Starting Epoch:', trainer.start_epoch)
print('INFO:PyTorch: Total Epoches:', trainer.train_epochs)
# train-eval loops
for epoch in range(trainer.start_epoch, trainer.train_epochs):
trainer.training(epoch)
if not trainer.no_val and ((epoch + 1) % args.eval_interval == 0):
trainer.validation(epoch)
trainer.train_writer.close()
trainer.val_writer.close()
示例10: main
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def main(*args, **kwargs):
"""
`kwargs`:
`configuration_filepath`: filepath for the `ini` configuration
"""
kwargs = {**kwargs, **_get_kwargs()}
# FIXME: This filepath handeling is messed up and not transparent as it should be
default_filepath = get_config_filepath()
configuration_filepath = kwargs.get('configuration_filepath')
if configuration_filepath is None:
configuration_filepath = default_filepath
# configuration is from an `ini` file
configuration = _get_config(configuration_filepath)
# setup some sane defaults
robot_name = _configuration_sane_defaults(configuration)
# Get the port configuration out of the configuration
port_config = _port_configuration_helper(configuration)
# create the settings manager using the port config
if _setproctitle:
_setproctitle.setproctitle('vexbot')
robot = Robot(robot_name, port_config)
robot.run()
示例11: predict_one
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def predict_one(self, data=None):
# TODO(reduce data in limited batch)
assert len(self.summary_dict) == 0, "still not support scalar summary in testing stage"
setproctitle.setproctitle('test epoch:' + str(self.cur_epoch))
self.read_timer.tic()
feed_dict, batch_size = self.next_feed(data)
self.read_timer.toc()
self.gpu_timer.tic()
res = self.sess.run([*self.graph_ops, *self.summary_dict.values()], feed_dict=feed_dict)
self.gpu_timer.toc()
if data is not None and len(data[0]) < self.cfg.num_gpus * batch_size:
for i in range(len(res)):
res[i] = res[i][:len(data[0])]
return res
示例12: wrap_worker__run
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def wrap_worker__run(self):
"""
While a Mitogen strategy is active, trap WorkerProcess.run() calls and use
the opportunity to set the worker's name in the process list and log
output, activate profiling if requested, and bind the worker to a specific
CPU.
"""
if setproctitle:
setproctitle.setproctitle('worker:%s task:%s' % (
self._host.name,
self._task.action,
))
# Ignore parent's attempts to murder us when we still need to write
# profiling output.
if mitogen.core._profile_hook.__name__ != '_profile_hook':
signal.signal(signal.SIGTERM, signal.SIG_IGN)
ansible_mitogen.logging.set_process_name('task')
ansible_mitogen.affinity.policy.assign_worker()
return mitogen.core._profile_hook('WorkerProcess',
lambda: worker__run(self)
)
示例13: start
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def start(self):
self.pid = os.fork()
if self.pid:
# Wait for child to boot before continuing.
mitogen.core.io_op(self.model.parent_sock.recv, 1)
return
ansible_mitogen.logging.set_process_name('mux:' + str(self.index))
if setproctitle:
setproctitle.setproctitle('mitogen mux:%s (%s)' % (
self.index,
os.path.basename(self.path),
))
self.model.parent_sock.close()
self.model.parent_sock = None
try:
try:
self.worker_main()
except Exception:
LOG.exception('worker_main() crashed')
finally:
sys.exit()
示例14: __init__
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [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()
示例15: start
# 需要導入模塊: import setproctitle [as 別名]
# 或者: from setproctitle import setproctitle [as 別名]
def start(self, name="neutron-server", desc=None):
"""Start the worker.
If worker_process_count is greater than 0, a callback notification
is sent. Subclasses should call this method before doing their
own start() work.
Automatically sets the process title to indicate that this is a
child worker, customizable via the name and desc arguments.
:returns: None
"""
# If we are a child process, set our proctitle to something useful
self.setproctitle(name, desc)
if self.worker_process_count > 0:
registry.notify(resources.PROCESS, events.AFTER_INIT, self.start)