def workerRun(objClasses, resultContainer, pparam, lockList): objHandler = ObjHandler() objHandler.loadClasses(objClasses, None) from multiprocessing.pool import ThreadPool thpool = ThreadPool(len(lockList)) while 1: callId = pparam.recv() thpool.apply_async(func=wokerCall, args=(callId, resultContainer, pparam, lockList, objHandler))
def __callObjFun__(self, reqPath, reqParam): try: return self.ws.callObjFunInworker(reqPath, reqParam) except WorkerManager.WorkerFullException as ex: slog.warn(str(ex)) except: slog.error(str(traceback.format_exc())) # If worker is full or exception, deal request in main process return ObjHandler.__callObjFun__(self, reqPath, reqParam)
def createCservice(servicePath, cserviceInfo, cserviceProxy, stubFiles, rHandler): servicePath = servicePath.strip().lower() if servicePath == "": servicePath = "cservice" if rHandler.handlers.__contains__(servicePath): return from libs.refrect import DynamicLoader ignoreImportExcept = False DynamicLoader.getClassFromFile(None, ignoreImportExcept, *stubFiles) slog.info("Service: %s" % ", ".join([c[0].__name__ for c in cserviceInfo])) cservice = ObjHandler() cservice.loadClasses(cserviceInfo, rHandler) rHandler.addHandler(servicePath, cservice) for cserviceCls, handleUrl in cserviceProxy: rHandler.addHandler(handleUrl.lower(), cserviceCls(cservice.objs))
def initCservice(): global cservice objClasses = [(SampleServerApi, None, {})] if workerSize <= 0: cservice = ObjHandler() cservice.loadClasses(objClasses, None) else: from server.objhandle import ProcessObjHandler, WorkerScheduler ws = WorkerScheduler(objClasses, workerSize, lockSize) cservice = ProcessObjHandler(ws) cservice.loadClasses(objClasses, None)
def __init__(self, ws): ObjHandler.__init__(self) assert ws is not None self.ws = ws