o
    /wi                     @  s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ er=d dlZd d	lmZ d d
lmZ nedZedZedZeeZdZ	d"d#ddZe	dddddd$d d!ZdS )%    )annotations)ThreadPoolExecutor)TYPE_CHECKING)logging)experimental_func)_LazyImport)BaseStorageN)servicer)api_pb2_grpcgrpczoptuna.storages._grpc.servicerz1optuna.storages._grpc.auto_generated.api_pb2_grpcz%Y-%m-%d %H:%M:%S.%fstorager   hoststrportintthread_poolThreadPoolExecutor | Nonereturngrpc.Serverc                 C  s>   t |ptdd}tt| | || d|  |S )N
   )max_workers:)r   serverr   r
   $add_StorageServiceServicer_to_servergrpc_servicerOptunaStorageProxyServiceadd_insecure_portr   r   r   r   r    r   Y/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/optuna/storages/_grpc/server.pymake_server   s   
r    z4.2.0	localhosti2  )r   r   r   Nonec                C  sB   t | |||}|  td| d|  td |  dS )a  Run a gRPC server for the given storage URL, host, and port.

    Example:

        Run this server with the following way:

        .. code::

            from optuna.storages import run_grpc_proxy_server
            from optuna.storages import get_storage

            storage = get_storage("mysql+pymysql://<user>:<pass>@<host>/<dbname>[?<options>]")
            run_grpc_proxy_server(storage, host="localhost", port=13000)

        Please refer to the client class :class:`~optuna.storages.GrpcStorageProxy` for
        the client usage. Please use :func:`~optuna.storages.get_storage` instead of
        :class:`~optuna.storages.RDBStorage` since ``RDBStorage`` by itself does not use cache in
        process and it may cause significant slowdown.

    Args:
        storage: A storage object to proxy.
        host: Hostname to listen on.
        port: Port to listen on.
        thread_pool:
            Thread pool to use for the server. If :obj:`None`, a default thread pool
            with 10 workers will be used.

    .. warning::

        Currently, gRPC storage proxy does not support the
        :class:`~optuna.storages.JournalStorage`. This issue is tracked in
        https://github.com/optuna/optuna/issues/6084. Please use
        :class:`~optuna.storages.RDBStorage` instead.
    zServer started at r   zListening...N)r    start_loggerinfowait_for_terminationr   r   r   r   run_grpc_proxy_server&   s
   *
r'   )N)
r   r   r   r   r   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r"   )
__future__r   concurrent.futuresr   typingr   optunar   optuna._experimentalr   optuna._importsr   optuna.storagesr   r   optuna.storages._grpcr	   r   $optuna.storages._grpc.auto_generatedr
   
get_logger__name__r$   DATETIME_FORMATr    r'   r   r   r   r   <module>   s.    
