Search code examples
pythonpython-multiprocessingmultiprocessing-manager

Change the spawned process name for Python multiprocessing manager


I want to change the process name of the spawned multiprocessing's manager SyncManager using setproctitle, I tried extending multiprocessing.managers.SyncManager:

class MySyncManager(multiprocessing.managers.SyncManager):
    def __init__(self):
        super(MySyncManager, self).__init__()
        self.daemon=True

    def run(self):
        setproctitle.setproctitle('MySyncManager')
        super(MySyncManager, self).run()


if __name__ == '__main__':
    mySyncManager = MySyncManager()
    mySyncManager.start()

But it doesn't seem to work. Any idea how to do it?


Solution

  • I found the solution to my question.

    def changeProcessTitle(title):
        from setproctitle import setproctitle
        setproctitle(title)
    
    class MySyncManager(multiprocessing.managers.SyncManager):
        def __init__(self):
            super(MySyncManager, self).__init__()
            self.daemon=True
    
    if __name__ == '__main__':
        mySyncManager = MySyncManager()
        initArgs = ('MySyncManager', )
        mySyncManager.start(changeProcessTitle, initArgs)