U
    /e                     @  s&  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	Z	d dl
Z
d dlmZ d dlmZ d dlmZ d dlmZmZ edZe
jddd	Ze
jd
eddde
jdeddde
jdeddde
jdeddde
jdeddde
jdeddde
jdeddde
jdeddde
jdedddd e
jd!d"dd#d$d%e
jd&d'd#d#d(d%e
jd)d#d*d+e
jd,edd-de
jd.ed#dd/d e
jd0edd1de
jd2edd3de
jd4eddd5d6e
jd7d8e
jed9e
jd:ded;d<e
 d=d> Z e!d?kr"e   dS )@    )annotationsN)	Scheduler)wait_for_signals)validate_preload_argv)enable_proctitle_on_childrenenable_proctitle_on_currentzdistributed.schedulerT)existsZresolve_path	scheduler)Zignore_unknown_options)nameZcontext_settingsz--host z"URI, IP or hostname of this server)typedefaulthelpz--portzServing portz--interfacez0Preferred network interface like 'eth0' or 'ib0'z
--protocolzProtocol like tcp, tls, or ucxz--tls-ca-filez'CA cert(s) file for TLS (in PEM format)z
--tls-certz(certificate file for TLS (in PEM format)z	--tls-keyz(private key file for TLS (in PEM format)z--dashboard-addressz:8787z4Address on which to listen for diagnostics dashboard)r   r   Zshow_defaultr   z--dashboard/--no-dashboard	dashboardFz+Launch the Dashboard [default: --dashboard])r   requiredr   z--jupyter/--no-jupyterjupyterzStart a Jupyter Server in the same process.  Warning: This will makeit possible for anyone with access to your dashboard address to runPython codez--show/--no-showzShow web UI [default: --show])r   r   z--dashboard-prefixzPrefix for the dashboard appz--use-xheadersz<User xheaders in dashboard app for ssl termination in headerz
--pid-filezFile to write the process PIDz--scheduler-filezFile to write connection information. This may be a good way to share connection information if your cluster is on a shared network file system.z	--preloadz[Module that should be loaded by the scheduler process  like "foo.bar" or "/path/to/foo.py".)r   multipleZis_eagerr   Zpreload_argv)nargsr   callbackz--idle-timeoutz4Time of inactivity after which to kill the scheduler)r   r   r   c              
     s2  dt jd krtdt t \}}}t|d |d |d  t  t	  rddkrd
d	rzd	krz	
d	rdkrdd 
dD ntdkrrtd	st	trd
gdgt	d   nd
t	tsttr,t	tr$ttr$tt	kr,tddd d|	fd|
fd|ffD 
sh|	sd|
sd|rhdrtd}|tt  W 5 Q R X fdd}t| t jdrddl}||j\}}t||d }||j||f  	
f
dd}zt"#|  W 5 t !d X dS )zLaunch a Dask scheduler.zdask-schedulerr   zbdask-scheduler is deprecated and will be removed in a future release; use `dask scheduler` instead   ,c                 S  s   g | ]}t |qS  )int).0pr   r   B/tmp/pip-unpacked-wheel-g426oqom/distributed/cli/dask_scheduler.py
<listcomp>   s     zmain.<locals>.<listcomp>Nz:\diR"     z8--protocol and --port must both be lists of equal lengthc                 S  s   i | ]\}}|d k	r||qS Nr   )r   kvr   r   r   
<dictcomp>   s    zmain.<locals>.<dictcomp>tls_ca_fileZtls_scheduler_certZtls_scheduler_keyztls://wc                     s   t j rt   d S r   )ospathr   remover   )pid_filer   r   del_pid_file   s    zmain.<locals>.del_pid_filelinux   c                    s   t d tf 
	d	 t d  fdd}  fdd}t| }t|  }tj||gtjdI d H \}}dd	 |D  t d
 j d S )Nz/-----------------------------------------------)	securityhostportprotocol	interfacer   dashboard_addressZhttp_prefixr   c                     s    I dH     I dH  dS )z/Wait for the scheduler to initialize and finishN)finishedr   r	   r   r   wait_for_scheduler_to_finish   s    
z7main.<locals>.run.<locals>.wait_for_scheduler_to_finishc                     s   t  I dH    I dH  dS )zVWait for SIGINT or SIGTERM and close the scheduler upon receiving one of those signalsN)r   closer   r3   r   r   wait_for_signals_and_close   s    z5main.<locals>.run.<locals>.wait_for_signals_and_close)Zreturn_whenc                 S  s   g | ]}|  qS r   )result)r   Ztaskr   r   r   r      s     z%main.<locals>.run.<locals>.<listcomp>zStopped scheduler at %r)loggerinfor   asyncioZcreate_taskwaitZFIRST_COMPLETEDaddress)r4   r6   Zwait_for_signals_and_close_taskZ!wait_for_scheduler_to_finish_taskdone_)
r   r1   dashboard_prefixr-   r0   r   kwargsr.   r/   secr3   r   run   s:    


zmain.<locals>.runzEnd scheduler)$sysargvwarningswarnFutureWarninggcZget_thresholdset_thresholdr   r   splitr   research
isinstancelistlen
ValueErroropenwritestrr%   getpidatexitregisterplatform
startswithresourceZ	getrlimitZRLIMIT_NOFILEmaxZ	setrlimitr8   r9   r:   rB   )r-   r.   r/   r0   showr   r?   Zuse_xheadersr(   r#   Ztls_certZtls_keyr1   r   r@   Zg0Zg1Zg2fr)   rY   ZsofthardlimitrB   r   )r   r1   r?   r-   r0   r   r@   r(   r.   r/   rA   r   main   sd    o




*r_   __main__)"
__future__r   r:   rU   rH   loggingr%   rK   rC   rE   ZclickZdistributedr   Zdistributed._signalsr   Zdistributed.preloadingr   Zdistributed.proctitler   r   	getLoggerr8   PathZpem_file_option_typecommanddictoptionrS   boolargumentZUNPROCESSEDZversion_optionr_   __name__r   r   r   r   <module>   s   
   	      0 
