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 stateg = 10000 class MathClass (object): def add (self, x, y): return x + y + g def mul (self, x, y): return x * yclass MathManager (BaseManager): passMathManager. 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 BaseManagerclass MathClass (object): pass class MathManager (BaseManager): passMathManager. register ('Math', MathClass) manager = MathManager (address = ('', 50000), authkey = 'abc') manager. connect () m = manager. math () print m. add (100, 20)