def create_async_client( io_loop, request, path, station_coordinates_callback=None, event_info_callback=None, travel_time_callback=None, ): application = get_application() application.db = find_and_open_files(path=path) application.station_coordinates_callback = station_coordinates_callback application.event_info_callback = event_info_callback application.travel_time_callback = travel_time_callback application.max_size_of_finite_sources = 1000 # Build server. sock, port = bind_unused_port() server = HTTPServer(application) server.add_sockets([sock]) def _stop(): server.stop() if hasattr(server, "close_all_connections"): io_loop.run_sync(server.close_all_connections, timeout=30) request.addfinalizer(_stop) # Build client. client = AsyncHTTPClient() client.loop = io_loop def _close(): client.close() request.addfinalizer(_close) client.application = application client.filepath = path client.port = port # Flag to help deal with forward/backwards databases. b = os.path.basename(path) if "bwd" in b or "horizontal_only" in b or "vertical_only" in b: client.is_reciprocal = True client.source_depth = 0.0 else: client.is_reciprocal = False client.source_depth = application.db.info.source_depth * 1000 client.info = application.db.info return client