def __init__(self,port=None): """@param port: The port on which the server should listen""" if port==None: port=config().getint("Metaserver","port") foamLogger("server").info("Starting Server up") self.pid=os.getpid() try: self.webserver = xmlrpclib.ServerProxy(WEBSERVER_RPCURL) self.servers={} self.dataLock=Lock() self.startupLock=Lock() self.collect() self.checker=MetaChecker(self) self.checker.setDaemon(True) self.checker.start() self._server=ServerBase(('',port),logRequests=False) self._server.register_instance(self) self._server.register_introspection_functions() self._server.serve_forever() # occasional errors with "Broken pipe" except KeyboardInterrupt: foamLogger("server").warning("Keyboard interrupt") except socket.error,reason: foamLogger("server").error("Socket Error: "+str(reason)) print "Can't start server, Problem with socket: ",reason[1]
def __init__(self,run=None,master=None,lines=100): """ @param run: The thread that controls the run @param master: The Runner-Object that controls everything @param lines: the number of lines the server should remember """ Thread.__init__(self) self.isRegistered=False tries=0 maxTries=length=config().getint("Network","socketRetries") ok=False while not ok and tries<maxTries: ok=True tries+=1 self._port=findFreePort() self._running=False if self._port<0: foamLogger().warning("Could not get a free port. Server not started") return try: foamLogger().info("Serving on port %d" % self._port) self._server=ServerBase(('',self._port),logRequests=False) self._server.register_introspection_functions() self._answerer=FoamAnswerer(run=run,master=master,lines=lines,foamserver=self) self._server.register_instance(self._answerer) self._server.register_function(self.killServer) self._server.register_function(self.kill) if run: self._server.register_function(run.cpuTime) self._server.register_function(run.cpuUserTime) self._server.register_function(run.cpuSystemTime) self._server.register_function(run.wallTime) self._server.register_function(run.usedMemory) except socket.error,reason: ok=False warning("Could not start on port",self._port,"althoug it was promised. Try:",tries,"of",maxTries) foamLogger().warning("Could not get port %d - SocketError: %s. Try %d of %d" % (self._port,str(reason),tries,maxTries)) sleep(2+20*random())