1

Is it possible to set the name of the Processes spawned by multiprocessing.Process or billiard.Process. SOmething like:

import billiard
for d in list:
    processes.append(billiard.Process(target=evaluate))
for p in processes:
    p.name =  'someID'
    p.start()

I want to find those specific processes afterwards while they are running with:

import psutil
for proc in psutil.process_iter():
    if proc.name() == 'someID':
        print(proc)
Varlor
  • 1,421
  • 3
  • 22
  • 46

1 Answers1

1

If I may suggest, use process id instead of process name - thats way better, and would save you a whole lot of trouble.. since you just need a reference to the process later, use their ids instead of name.

Python 3.6 Official Docs have illustrated a very good way of playing around with process ids. Here is a snippet from the documentation

from multiprocessing import Process
import os

def info(title):
    print(title)
    print('module name:', __name__)
    print('parent process:', os.getppid())
    print('process id:', os.getpid())

def f(name):
    info('function f')
    print('hello', name)

if __name__ == '__main__':
    info('main line')
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()

Also I see, Celery in your tags, if you're going to play with concurrent processes, I would recommend Supervisord instead. Gives you a very good control over the processes, if you're having a small scale project.

Ronnie
  • 992
  • 1
  • 9
  • 25
  • Thanks for the input for celery processes. I will definetly have a look on it. Because I saw that every process no matter if a subprocess with billiard.multiprocessing or a standard process has the name "celery". But also therefore it would be great to define a name for the kind of celery task. When not using celery setting the process name with process.name does not seem to work. I thought it would be great thing to name them because afterwards i can delete whole grous of processes without store their ids somewhere. – Varlor Jun 27 '19 at 07:43