U
    /e                     @  sL  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZmZ ejjZejejedZeeZeeZW 5 Q R X eje dddd	d
dddddddddddddddddddddd d!d"d#d$Zeje eeZd%d& Zd'd( Zd)d* Z d+d, Z!d-d. Z"d/d0 Z#e"ejj e#ejj dS )1    )annotationsN)import_required)WINDOWSlogging_nameszdistributed.yamlz&distributed.scheduler.allowed-failureszdistributed.scheduler.bandwidthz'distributed.scheduler.default-data-sizez+distributed.scheduler.transition-log-lengthz#distributed.scheduler.work-stealingz distributed.scheduler.worker-ttlz)distributed.worker.multiprocessing-methodz#distributed.worker.use-file-lockingz#distributed.worker.profile.intervalz distributed.worker.profile.cyclez distributed.worker.memory.targetzdistributed.worker.memory.spillzdistributed.worker.memory.pausez#distributed.worker.memory.terminatezdistributed.client.heartbeatzdistributed.comm.compressionz!distributed.comm.timeouts.connectzdistributed.comm.timeouts.tcpzdistributed.comm.default-schemezdistributed.comm.socket-backlogz+distributed.comm.recent-messages-log-lengthzdistributed.dashboard.linkz!distributed.dashboard.export-toolzdistributed.admin.tick.intervalzdistributed.admin.tick.limitzdistributed.admin.log-lengthdistributed.admin.log-formatzdistributed.admin.pdb-on-errzdistributed.comm.ucxzdistributed.rmm)zallowed-failures	bandwidthzdefault-data-sizeztransition-log-lengthzwork-stealingz
worker-ttlzmultiprocessing-methodzuse-file-lockingzprofile-intervalzprofile-cycle-intervalzworker-memory-targetzworker-memory-spillzworker-memory-pausezworker-memory-terminatezheartbeat-intervalcompressionzconnect-timeoutztcp-timeoutzdefault-schemezsocket-backlogzrecent-messages-log-lengthzdiagnostics-linkzbokeh-export-toolz	tick-timeztick-maximum-delayz
log-lengthz
log-formatz
pdb-on-errZucxZrmmc           
      C  s   dddddd}t | }||di  ttj}|tt	j
jd| d | D ]\}}t|trxt|  }t|}|| d	}d
}|dD ]4}	|d	krt|	}n
||	 ||jkrd} qq|sZ|| qZd	S )z
    Initialize logging using the "old-style" configuration scheme, e.g.:
        {
        'logging': {
            'distributed': 'info',
            'tornado': 'critical',
            'tornado.application': 'error',
            }
        }
    infowarningerrorcritical)distributedzdistributed.clientZbokehtornadoztornado.applicationloggingr   )configNF.T)_find_logging_configupdategetr   StreamHandlersysstderrsetFormatter	Formatterdaskr   items
isinstancestrr   upper	getLoggersetLevelsplitgetChildhandlers
addHandler)
r   loggersbase_confighandlernamelevelloggerZancZalready_registeredZancestor r+   6/tmp/pip-unpacked-wheel-g426oqom/distributed/config.py_initialize_logging_old_styleG   s<    




r-   c                 C  s   t | }tj|d dS )z
    Initialize logging using logging's "Configuration dictionary schema".
    (ref.: https://docs.python.org/3/library/logging.config.html#configuration-dictionary-schema)
    r   N)r   r   r   
dictConfigr   r   r&   r+   r+   r,   _initialize_logging_new_styley   s    r0   c                 C  s"   t | }tjj|ddd dS )z
    Initialize logging using logging's "Configuration file format".
    (ref.: https://docs.python.org/3/howto/logging.html#configuring-logging)
    logging-file-configF)disable_existing_loggersN)r   r   r   
fileConfigr   r/   r+   r+   r,   _initialize_logging_file_config   s
     r4   c                 C  s,   ddh}||  di  @ r$| d S | S dS )z
    Look for the dictionary containing logging-specific configurations,
    starting in the 'distributed' dictionary and then trying the top-level
    r1   r   r   N)r   keys)r   Zlogging_keysr+   r+   r,   r      s    r   c                 C  sd   t | }d|kr*d|kr tdt|  n6|di }d|krXt|d |d< t|  nt|  d S )Nr1   r   zJConfig options 'logging-file-config' and 'logging' are mutually exclusive.version)r   RuntimeErrorr4   r   intr0   r-   )r   r&   Z
log_configr+   r+   r,   initialize_logging   s    

r9   c                 C  s\   t jd}|dkr(tdd}|  n0|dkrDtrXtt  nt	dt jd d S )Nzdistributed.admin.event-loopuvloopzThe distributed.admin.event-loop configuration value is set to 'uvloop' but the uvloop module is not installed

Please either change the config value or install one of the following
    conda install uvloop
    pip install uvloop>   asyncior   zWExpected distributed.admin.event-loop to be in ('asyncio', 'tornado', 'uvloop'), got %s)
r   r   r   r   installr   r;   Zset_event_loop_policyZWindowsSelectorEventLoopPolicy
ValueError)r   Z
event_loopr:   r+   r+   r,   initialize_event_loop   s    	

r>   )$
__future__r   r;   r   logging.configosr   Zyamlr   Z
dask.utilsr   Zdistributed.compatibilityr   r   r   pathjoindirname__file__fnopenfZ	safe_loaddefaultsZupdate_defaultsaliasesrenamer   __name__r*   r-   r0   r4   r   r9   r>   r+   r+   r+   r,   <module>   sn   
!	
2	