Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.util.rpc_aggregator Namespace Reference

Classes

class  RPCYielder

Functions

def scheduler
def scheduler_simple

Variables

tuple INVALID = object()

Function Documentation

def MoinMoin.util.rpc_aggregator.scheduler (   multicall_func,
  handler,
  args,
  max_calls = 10,
  prepare_multicall_func = None 
)

Definition at line 56 of file rpc_aggregator.py.

00056 
00057 def scheduler(multicall_func, handler, args, max_calls=10, prepare_multicall_func=None):
00058     # all generator (or better, RPCYielder) instances
00059     gens = []
00060     # those instances that have to be queried in the next step again
00061     gens_todo = []
00062     # pending calls, stored as tuples: (generator, (funcname, (args,*)))
00063     call_list = []
00064 
00065     # instantiate generators
00066     for arg in args:
00067         gens.append(handler(arg))
00068     # schedule generators
00069     while gens:
00070         for gen in gens:
00071             if len(call_list) > max_calls:
00072                 gens_todo.append(gen)
00073                 continue
00074             call = gen.fetch_call()
00075             if call is not None:
00076                 call_list.append((gen, call))
00077                 gens_todo.append(gen)
00078         if call_list:
00079             if prepare_multicall_func is not None:
00080                 pre_calls = [(RPCYielder(0), x) for x in prepare_multicall_func()]
00081                 call_list = pre_calls + call_list
00082 
00083             m = multicall_func()
00084             gens_result = [] # generators that will get a result
00085             for gen, (func, args) in call_list:
00086                 gens_result.append(gen)
00087                 getattr(m, func)(*args) # register call
00088             result = iter(m()) # execute multicall
00089             for gen in gens_result:
00090                 try:
00091                     item = result.next()
00092                 except xmlrpclib.Fault, e:
00093                     # this exception is reraised by the RPCYielder
00094                     item = e
00095                 gen.set_result(item)
00096             call_list = []
00097         gens = gens_todo
00098         gens_todo = []
00099 

def MoinMoin.util.rpc_aggregator.scheduler_simple (   multicall_func,
  handler,
  args 
)

Definition at line 100 of file rpc_aggregator.py.

00100 
00101 def scheduler_simple(multicall_func, handler, args):
00102     for arg in args:
00103         cur_handler = handler(arg)
00104         while 1:
00105             call = cur_handler.fetch_call()
00106             if call is not None:
00107                 func, arg = call
00108                 m = multicall_func()
00109                 getattr(m, func)(arg) # register call
00110                 result = iter(m()) # execute multicall
00111                 try:
00112                     item = result.next()
00113                 except xmlrpclib.Fault, e:
00114                     # this exception is reraised by the RPCYielder
00115                     item = e
00116                 cur_handler.set_result(item)
00117             else:
00118                 break

Variable Documentation

Definition at line 13 of file rpc_aggregator.py.