python multiprocessing example   发布时间:2017-09-12 14:29:38

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)

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:上海网站建设 http://www.flpsz.com