Ejemplo n.º 1
0
def server_instance(managed_tmpdir, worker_id):
    from hangar import serve

    address = f'localhost:{randint(50000, 59999)}'
    base_tmpdir = pjoin(managed_tmpdir, f'{worker_id[-1]}')
    mkdir(base_tmpdir)
    server, hangserver, _ = serve(base_tmpdir, overwrite=True, channel_address=address)
    server.start()
    yield address

    hangserver.env._close_environments()
    server.stop(0.0)
    time.sleep(0.2)
    if platform.system() == 'Windows':
        # time for open file handles to close before tmp dir can be removed.
        time.sleep(0.3)
Ejemplo n.º 2
0
def server_instance_nbytes_limit(managed_tmpdir, worker_id):
    from hangar import serve

    address = f'localhost:{randint(50000, 59999)}'
    base_tmpdir = pjoin(managed_tmpdir, f'{worker_id[-1]}')
    mkdir(base_tmpdir)
    server, hangserver, _ = serve(base_tmpdir,
                                  overwrite=True,
                                  channel_address=address)
    hangserver.CFG['SERVER_GRPC']['fetch_max_nbytes'] = '100000'
    hangserver.CFG['CLIENT_GRPC']['push_max_nbytes'] = '100000'
    server.start()
    yield address

    hangserver.env._close_environments()
    server.stop(0.1)
    time.sleep(0.2)
    if platform.system() == 'Windows':
        # time for open file handles to close before tmp dir can be removed.
        time.sleep(0.3)
Ejemplo n.º 3
0
def server(overwrite, ip, port, timeout):
    """Start a hangar server, initializing one if does not exist.

    The server is configured to top working in 24 Hours from the time it was
    initially started. To modify this value, please see the ``--timeout``
    parameter.

    The hangar server directory layout, contents, and access conventions are
    similar, though significantly different enough to the regular user "client"
    implementation that it is not possible to fully access all information via
    regular API methods. These changes occur as a result of the uniformity of
    operations promised by both the RPC structure and negotiations between the
    client/server upon connection.

    More simply put, we know more, so we can optimize access more; similar, but
    not identical.
    """
    from hangar import serve

    P = os.getcwd()
    ip_port = f'{ip}:{port}'
    server, hangserver, channel_address = serve(P,
                                                overwrite,
                                                channel_address=ip_port)
    server.start()
    click.echo(f'Hangar Server Started')
    click.echo(f'* Start Time: {time.asctime()}')
    click.echo(f'* Base Directory Path: {P}')
    click.echo(f'* Operating on `IP_ADDRESS:PORT`: {channel_address}')
    try:
        startTime = time.time()
        while True:
            time.sleep(0.1)
            if time.time() - startTime > timeout:
                raise SystemExit
    except (KeyboardInterrupt, SystemExit):
        click.echo(f'Server Stopped at Time: {time.asctime()}')
        hangserver.env._close_environments()
        server.stop(0)
Ejemplo n.º 4
0
def server(overwrite):
    P = os.getcwd()
    if overwrite:
        serve(P, True)
    else:
        serve(P, False)