Esempio n. 1
0
def launchExecutor(executor):
    # Start executor that will run pipeline stages

    # getIpAddress is similar to socket.gethostbyname(...)
    # but uses a hack to attempt to avoid returning localhost (127....)
    network_address = Pyro4.socketutil.getIpAddress(socket.gethostname(),
                                                    workaround127=True,
                                                    ipVersion=4)
    daemon = Pyro4.core.Daemon(host=network_address)
    clientURI = daemon.register(executor)

    # find the URI of the server:
    if executor.ns:
        ns = Pyro4.locateNS()
        #ns.register("executor", executor, safe=True)
        serverURI = ns.lookup("pipeline")
    else:
        try:
            uf = open(executor.uri_file)
            serverURI = Pyro4.URI(uf.readline())
            uf.close()
        except:
            logger.exception("Problem opening the specified uri file:")
            raise

    p = Pyro4.Proxy(serverURI)
    # Register the executor with the pipeline
    # the following command only works if the server is alive. Currently if that's
    # not the case, the executor will die which is okay, but this should be
    # more properly handled: a more elegant check to verify the server is running
    p.registerClient(clientURI.asString(), executor.mem)

    executor.registeredWithServer()
    executor.setClientURI(clientURI.asString())
    executor.setServerURI(serverURI.asString())
    executor.setProxyForServer(p)

    logger.info("Connected to %s", serverURI)
    logger.info("Client URI is %s", clientURI)

    executor.connection_time_with_server = time.time()
    logger.info("Connected to the server at: %s",
                datetime.isoformat(datetime.now(), " "))

    executor.initializePool()

    logger.debug("Executor daemon running at: %s", daemon.locationStr)
    try:
        # run the daemon, not the executor mainLoop, in a new thread
        # so that mainLoop exceptions (e.g., if we lose contact with the server)
        # cause us to shutdown (as Python makes it tedious to re-throw to calling thread)
        t = threading.Thread(target=daemon.requestLoop)
        t.daemon = True
        t.start()
        h = threading.Thread(target=executor.heartbeat)
        h.daemon = True
        h.start()
        executor.mainLoop()
    except KeyboardInterrupt:
        logger.exception(
            "Caught keyboard interrupt. Shutting down executor...")
        executor.generalShutdownCall()
        #daemon.shutdown()
        sys.exit(0)
    except Exception:
        logger.exception(
            "Error during executor loop. Shutting down executor...")
        executor.generalShutdownCall()
        #daemon.shutdown()
        sys.exit(0)
    else:
        executor.completeAndExitChildren()
        logger.info("Executor shutting down.")
        daemon.shutdown()
        t.join()
def main():

    my_uri = Pyro4.URI(
        'PYRO:[email protected]:37875')

    print(my_uri)
Esempio n. 3
0
 def get_rpc_client(self, hostname, port):
     import Pyro4
     uri = Pyro4.URI("PYRO:node_manager@%s:%d" % (hostname, port))
     proxy = Pyro4.Proxy(uri)
     return proxy, proxy._pyroRelease
if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument("uri_file",
                        type=str,
                        help="file containing server's URI")

    options = parser.parse_args()

    uri_file = options.uri_file

    # find the server
    try:
        uf = open(uri_file)
        serverURI = Pyro4.URI(uf.readline())
        uf.close()
    except:
        print("There is a problem opening the specified uri file: %s" %
              uri_file)
        raise

    proxyServer = Pyro4.Proxy(serverURI)

    # total number of stages in the pipeline:
    numStages = proxyServer.getTotalNumberOfStages()
    processedStages = proxyServer.getNumberProcessedStages()
    print("Total number of stages in the pipeline: ", numStages)
    print("Number of stages already processed:     ", processedStages, "\n")

    # some info about executors