微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更改 Python 多处理管理器的衍生进程名称

如何解决更改 Python 多处理管理器的衍生进程名称

我想使用 setproctitle 更改生成的多处理管理器 SyncManager 的进程名称,我尝试扩展 multiprocessing.managers.SyncManager:

def Game_Board(rows,columns):
    max_columns = 100
    max_rows = 50
    rows = int(rows)
    columns = int(columns)
    if columns <= max_columns and rows <= max_rows:
        for r in range((rows-1)*2+1):
            if r%2 == 1:
                print("-"*(2*columns-1))
            else:
                print(" |"*(columns-1))
    else:
        print("rows and columns are above table values")
    return

Print_Board = Game_Board(50,100) 
print(Print_Board)

但是好像不行。知道怎么做吗?

解决方法

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

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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。