0

我想使用 setproctitle 更改生成的多处理管理器 SyncManager 的进程名称,我尝试扩展 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()

但这似乎不起作用。知道怎么做吗?

4

1 回答 1

0

我找到了我的问题的解决方案。

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)
于 2021-05-30T09:24:28.880 回答