def start_client_or_server(clientGenerator, serverGenerator, resources,
                           script):
    """start controller, client or server depending on whether
    we get coordinator argument from the command-line args.

    Client must be a generator function that takes Processor as argument,
    and uses it as an iterator.
    Also, clientGenerator must yield the IDs that the Processor provides
    (this structure allows us to trap all exceptions from clientGenerator,
    while allowing it to do resource initializations that would be
    much less elegant in a callback function.)

    Server must be a function that returns an iterator (e.g. a generator).
    Resources is a list of strings naming the resources we need
    copied to local host for client to be able to do its work.

    Both client and server constructors use **kwargs to get command
    line arguments (passed as GNU-style --foo=bar;
    see the constructor arguments to see the list of
    options that each can be passed.

    #CALL LIKE THIS FROM yourscript.py:
    import coordinator
    if __name__ == '__main__':
      coordinator.start_client_or_server(clientGen, serverGen,
        resources,__file__)

    To start the resource controller:
      python coordinator.py --rc=NAME [options]

    To start a job coordinator:
      python yourscript.py NAME [--rc_url=URL] [options]

    To start a job processor:
      python yourscript.py --url=URL --rc_url=URL [options]"""
    d, l = parse_argv()
    if 'url' in d: # WE ARE A CLIENT!
        client = Processor(**d)
        time.sleep(5) # GIVE THE SERVER SOME BREATHING SPACE
        client.run_all(clientGenerator, **d)
    elif 'rc' in d: # WE ARE THE RESOURCE CONTROLLER
        rc_server = ResourceController(**d) # NAME FOR THIS CONTROLLER...
        detach_as_demon_process(rc_server)
        rc_server() # START THE SERVER
    else: # WE ARE A SERVER
        try: # PASS OUR KWARGS TO THE SERVER FUNCTION
            it = serverGenerator(**d)
        except __HOLE__: # DOESN'T WANT ANY ARGS?
            it = serverGenerator()
        server = Coordinator(l[0], script, it, resources, **d)
        detach_as_demon_process(server)
        server() # START THE SERVER
dataset/ETHPy150Open cjlee112/pygr/pygr/coordinator.py/start_client_or_server