首页 > 代码库 > python multiprocessing example
python multiprocessing example
python multiprocessing example
Server Code:
#!/usr/bin/python #-*- coding: UTF-8 -*- # mpserver.py # # Queues are thread and process safe. from multiprocessing.managers import BaseManager # g as a server process state g = 10000 class MathClass(object): def add(self, x, y): return x + y + g def mul(self, x, y): return x * y class MathManager(BaseManager): pass MathManager.register(‘Math‘, MathClass) manager = MathManager(address=(‘‘, 50000), authkey=‘abc‘) server = manager.get_server() server.serve_forever()
Client Code:
#!/usr/bin/python #-*- coding: UTF-8 -*- # mpclient.py # # Queues are thread and process safe. from multiprocessing.managers import BaseManager class MathClass(object): pass class MathManager(BaseManager): pass MathManager.register(‘Math‘, MathClass) manager = MathManager(address=(‘‘, 50000), authkey=‘abc‘) manager.connect() m = manager.Math() print m.add(100, 20)
python multiprocessing example
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。