Skip to content

Instantly share code, notes, and snippets.

@michelp
Created April 7, 2015 19:14
Show Gist options
  • Select an option

  • Save michelp/2cdde314da494a5eb3e3 to your computer and use it in GitHub Desktop.

Select an option

Save michelp/2cdde314da494a5eb3e3 to your computer and use it in GitHub Desktop.
if __name__ == '__main__':
import atexit
from multiprocessing import Process
device = zmq.devices.ProcessDevice(zmq.QUEUE, zmq.ROUTER, zmq.DEALER)
device.bind_in('ipc://bind_in')
device.bind_out('ipc://bind_out')
device.start()
def hello(name):
return 'hello %s' % name
def test(*args, **kwargs):
return [args, kwargs]
Worker.register('hello', hello)
Worker.register('test', test)
NUM_WORKERS = 10
procs = [Process(target=Worker('ipc://bind_out')) for i in range(NUM_WORKERS)]
for p in procs:
p.start()
c = Client('ipc://bind_in')
assert c.hello('dave') == 'hello dave'
assert c.test(1, 2, 3) == [(1, 2, 3), {}]
try:
c.foo()
except AttributeError:
pass
else:
assert False
atexit.register(lambda: [p.terminate() for p in procs])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment