Python setproctitle.setproctitle() Examples

The following are 30 code examples of setproctitle.setproctitle(). 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: streamserver.py    From pulseaudio-dlna with GNU General Public License v3.0 7 votes vote down vote up
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() 
Example #2
Source File: base.py    From lighttrack with MIT License 6 votes vote down vote up
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 
Example #3
Source File: base.py    From tf-cpn with MIT License 6 votes vote down vote up
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 
Example #4
Source File: __main__.py    From vexbot with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #5
Source File: train.py    From RMI with MIT License 6 votes vote down vote up
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() 
Example #6
Source File: base.py    From PoseFix_RELEASE with MIT License 6 votes vote down vote up
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 
Example #7
Source File: task.py    From ms_deisotope with Apache License 2.0 6 votes vote down vote up
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 
Example #8
Source File: strategy.py    From mitogen with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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)
    ) 
Example #9
Source File: process.py    From mitogen with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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() 
Example #10
Source File: base.py    From video-to-pose3D with MIT License 6 votes vote down vote up
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 
Example #11
Source File: driver_agent.py    From octavia with Apache License 2.0 6 votes vote down vote up
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 
Example #12
Source File: actor.py    From powerapi with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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() 
Example #13
Source File: worker.py    From neutron-lib with Apache License 2.0 6 votes vote down vote up
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) 
Example #14
Source File: cli.py    From fossor with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 
Example #15
Source File: listener.py    From pulseaudio-dlna with GNU General Public License v3.0 6 votes vote down vote up
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()') 
Example #16
Source File: daemon.py    From pulseaudio-dlna with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #17
Source File: worker.py    From neutron-lib with Apache License 2.0 6 votes vote down vote up
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 #18
Source File: test_supervisor.py    From simpleflow with MIT License 5 votes vote down vote up
def test_start(self):
        # dummy function used in following tests
        def sleep_long(seconds):
            setproctitle("simpleflow Worker(sleep_long, {})".format(seconds))
            time.sleep(seconds)

        # create a supervisor sub-process
        supervisor = Supervisor(sleep_long, arguments=(30,), nb_children=2, background=True)
        supervisor.start()

        # we need to wait a little here so the process starts and gets its name set
        # TODO: find a non-sleep approach to this
        self.wait(0.5)
        self.assertProcess(r'simpleflow Supervisor\(_payload_friendly_name=sleep_long, _nb_children=2\)')
        self.assertProcess(r'simpleflow Worker\(sleep_long, 30\)', count=2) 
Example #19
Source File: worker.py    From neutron-lib with Apache License 2.0 5 votes vote down vote up
def setproctitle(self, name="neutron-server", desc=None):
        if self._set_proctitle == "off" or os.getpid() == self._my_pid:
            return

        if not desc:
            desc = self.__class__.__name__

        proctitle = "%s: %s" % (name, desc)
        if self._set_proctitle == "on":
            proctitle += " (%s)" % self._parent_proctitle

        setproctitle.setproctitle(proctitle) 
Example #20
Source File: evaluate.py    From revolver with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main(experiment, model, weights, dataset, datatype, split, count, shot, save_seg, seed, gpu):
    setproctitle.setproctitle("eval-{}".format(experiment))
    args = locals()
    print("args: {}".format(args))

    exp_dir = './experiments/{}/'.format(experiment)
    if not os.path.isdir(exp_dir):
        raise Exception("Experiment {} does not exist.".format(experiment))

    if weights:
        # evaluate given model
        evaluations = [weights]
    else:
        # evaluate all models in iteration order
        # but skip existing evaluations
        evaluations = sorted(glob.glob(exp_dir + '*.pth'))

    # template the output path
    count_ = 'dense' if count == -1 else "{}sparse".format(count) if count else 'randsparse'
    output_fmt = '-{}-{}-{}-{}-{}shot-{}'.format(dataset, datatype, split, count_, shot, seed)
    output_fmt = model + '-iter{}' + output_fmt

    for weights in evaluations:
        # make output path
        iter_ = re.search('iter(\d+).pth', weights).group(1)
        hist_path = exp_dir + 'hist-' + output_fmt.format(iter_)
        seg_path = None
        if save_seg:
            seg_path = exp_dir + output_fmt.format(iter_)
            os.makedirs(seg_path, exist_ok=True)
        # skip existing
        if os.path.isfile(hist_path + '.npz'):
            print("skipping existing {}".format(hist_path))
            continue
        evaluate(model, weights, dataset, datatype, split, count, shot, seed, gpu, hist_path, seg_path) 
Example #21
Source File: proc.py    From HUAWEIOCR-2019 with MIT License 5 votes vote down vote up
def set_proc_name(name):
    try:
        import setproctitle
    except:
        print('Module setproctitle is not installed. Run:')
        print('\t: pip install setproctitle --user')
    setproctitle.setproctitle(name) 
Example #22
Source File: proc.py    From HUAWEIOCR-2019 with MIT License 5 votes vote down vote up
def set_proc_name(name):
    try:
        import setproctitle
    except:
        print('Module setproctitle is not installed. Run:')
        print('\t: pip install setproctitle --user')
    setproctitle.setproctitle(name) 
Example #23
Source File: proc.py    From HUAWEIOCR-2019 with MIT License 5 votes vote down vote up
def set_proc_name(name):
    try:
        import setproctitle
    except:
        print('Module setproctitle is not installed. Run:')
        print('\t: pip install setproctitle --user')
    setproctitle.setproctitle(name) 
Example #24
Source File: cli.py    From cloud-custodian with Apache License 2.0 5 votes vote down vote up
def main():
    parser = setup_parser()
    argcomplete.autocomplete(parser)
    options = parser.parse_args()
    if options.subparser is None:
        parser.print_help(file=sys.stderr)
        return sys.exit(2)

    _setup_logger(options)

    # Support the deprecated -c option
    if getattr(options, 'config', None) is not None:
        options.configs.append(options.config)

    config = Config.empty(**vars(options))

    try:
        command = options.command
        if not callable(command):
            command = getattr(
                importlib.import_module(command.rsplit('.', 1)[0]),
                command.rsplit('.', 1)[-1])

        # Set the process name to something cleaner
        process_name = [os.path.basename(sys.argv[0])]
        process_name.extend(sys.argv[1:])
        setproctitle(' '.join(process_name))
        command(config)
    except Exception:
        if not options.debug:
            raise
        traceback.print_exc()
        pdb.post_mortem(sys.exc_info()[-1]) 
Example #25
Source File: test_supervisor.py    From simpleflow with MIT License 5 votes vote down vote up
def test_maintain_the_pool_of_workers_if_not_terminating(self):
        # dummy function used in following tests
        def sleep_long(seconds):
            setproctitle("simpleflow Worker(sleep_long, {})".format(seconds))
            time.sleep(seconds)

        # retrieve workers (not great; TODO: move it to Supervisor class)
        def workers():
            return [
                p for p in Process().children(recursive=True)
                if "Worker(sleep_long" in p.name()
            ]

        # create a supervisor sub-process
        supervisor = Supervisor(sleep_long, arguments=(30,), nb_children=1, background=True)
        supervisor.start()

        # we need to wait a little here so the workers start
        self.wait(0.5)
        old_workers = workers()
        expect(len(old_workers)).to.equal(1)

        # now kill the worker
        old_workers[0].pid
        os.kill(workers()[0].pid, signal.SIGKILL)
        self.wait(0.5)

        # ... and check that the process has been replaced
        new_workers = workers()
        expect(len(new_workers)).to.equal(1)
        expect(new_workers[0].pid).to.not_be.equal(old_workers[0].pid)

    # NB: not in the Supervisor class but we want to benefit from the tearDown() 
Example #26
Source File: utils.py    From Decentralized-Internet with MIT License 5 votes vote down vote up
def run(self):
        setproctitle.setproctitle(self.name)
        super().run()


# Inspired by:
# - http://stackoverflow.com/a/24741694/597097 
Example #27
Source File: utils.py    From bigchaindb with Apache License 2.0 5 votes vote down vote up
def run(self):
        setproctitle.setproctitle(self.name)
        super().run()


# Inspired by:
# - http://stackoverflow.com/a/24741694/597097 
Example #28
Source File: worker.py    From ray with Apache License 2.0 5 votes vote down vote up
def _changeproctitle(title, next_title):
    setproctitle.setproctitle(title)
    try:
        yield
    finally:
        setproctitle.setproctitle(next_title) 
Example #29
Source File: __init__.py    From salt-broker with Apache License 2.0 5 votes vote down vote up
def appendproctitle(name):
    '''
    Append "name" to the current process title

    From: https://github.com/saltstack/salt/blob/v2014.7.1/salt/utils/__init__.py#L2377
    '''
    if HAS_SETPROCTITLE:
        setproctitle.setproctitle(setproctitle.getproctitle() + ' ' + name) 
Example #30
Source File: __init__.py    From pytest-salt with Apache License 2.0 5 votes vote down vote up
def set_proc_title(title):
    if HAS_SETPROCTITLE is False:
        return
    setproctitle.setproctitle('[{}] - {}'.format(title, setproctitle.getproctitle()))