Strange process names when using multiprocessing in python

Hi, the following is the code.

import time
from multiprocessing import Process
class Worker(Process):

def run(self):

    print(f'In {self.name}')
    time.sleep(2)

def main():

worker = Worker()
worker.start()

worker2 = Worker()
worker2.start()

worker.join()
worker2.join()

if name == ‘main’:
main()

with the following output:

In Worker-1

In Worker-2

[Finished in 2.109s]

I was confused. My question is, where do the names “Workr-1” and “Worker-2” come from? Many thanks.

Hi bsn,

You asked:

“My question is, where do the names “Workr-1” and “Worker-2” come from?
Many thanks.”

They are the default names generated if you don’t provide a name.
“Worker” is the name of the class, and each object is numbered in turn.
See the documentation:

https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process.name

2 Likes