Job server provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing. It support python 3, python2.7
go build -o jserver job_server/*.go
> jserver
- -log
- -couter
- -client localhost:8010
- -worker localhost:8011
import jclient
def echo(data):
return data
rpc = jclient.WorkerHandler('localhost', 8011)
rpc.add('echo', echo) # attach a method
rpc.serve()
rpc.close()
import jclient
rpc = jclient.ClientHandler('localhost', 8010)
result = rpc.call('echo', b'data') # call a method
rpc.close()
import asyncio
from jclient.async import WorkerAsyncHandler
@asyncio.coroutine
def ping(raw):
yield from asyncio.sleep(1)
return b'pong'
def echo(raw):
return raw
@asyncio.coroutine
def worker(loop):
rpc = WorkerAsyncHandler('localhost', 8011, loop=loop)
rpc.add('ping', ping)
rpc.add('echo', echo)
yield from rpc.serve()
loop = asyncio.get_event_loop()
loop.run_until_complete(worker(loop))
loop.close()
import asyncio
from jclient.async import ClientAsyncHandler
@asyncio.coroutine
def run(loop):
rpc = ClientAsyncHandler('localhost', 8010, loop=loop)
result = yield from rpc.call('ping', b'data')
print(result)
rpc.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))
loop.close()
Copyright (c) 2015 Oleg Nechaev [email protected]