B
    4\G                 @   sB  d dl mZmZ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mZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZmZ d d	lmZmZ ed
Zej dddZ!ej"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 d!ddd"d#d$ej$d%d"d&d'ej$d(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$d4de%d5d6ej$d7e%dddd8d9ej(d:d;ej)ed<d=d> Z*d?d@ Z+e,dAkr>e+  dS )B    )print_functiondivisionabsolute_importN)IOLoop)	Scheduler)Security)get_ip_interface)check_python_3install_signal_handlersuri_from_host_port)preload_modulesvalidate_preload_argv)enable_proctitle_on_childrenenable_proctitle_on_currentzdistributed.schedulerT)existsZresolve_path)Zignore_unknown_options)Z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--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--bokeh-portiS"  z!Bokeh port for visual diagnosticsz--bokeh/--no-bokeh_bokehFzLaunch Bokeh Web UI)r   show_defaultZrequiredr   z--show/--no-showzShow web UI)r   r   z--bokeh-whitelistz$IP addresses to whitelist for bokeh.)r   multipler   z--bokeh-prefixzPrefix for the bokeh appz--use-xheadersz8User xheaders in bokeh app for ssl termination in header)r   r   r   r   z
--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--local-directoryz"Directory to place scheduler files)r   r   r   z	--preloadz[Module that should be loaded by the scheduler process  like "foo.bar" or "/path/to/foo.py".)r   r   Zis_eagerr   r   preload_argv)nargsr   callbackc          
      sl  t   t  t|||d}| s.|s*|s*|r.d}  rpt d}|tt  W d Q R X  fdd}t	| d}|rtj
|st| d}ntjdd	}d}|tj
krtj
d
| tjdrd
d l}||j\}}t||d }||j||f |
r | rtdnt|
} t| |d}t }td i }|ry$d
dlm } |d|if|d|f< W nR t!k
r } z2t|drtd ntdt|  W d d }~X Y nX t"|||	|d}|#| |st$j%&d}|st$j%&d}t'||||d td| td t(| z|#  |)  W d |*  |rZt+,| td| X d S )N)tls_ca_fileZtls_scheduler_certZtls_scheduler_keyztls://wc                  s   t j rt   d S )N)ospathr   remove )pid_filer!   =lib/python3.7/site-packages/distributed/cli/dask_scheduler.pydel_pid_fileV   s    zmain.<locals>.del_pid_fileFTz
scheduler-)prefixr   Zlinux   z'Can not specify both interface and hostiR"  z/-----------------------------------------------)BokehSchedulerr%   ZbokehzNo module namedz1Web dashboard not loaded.  Unable to import bokehzUnable to import bokeh: %s)loopservicesscheduler_fileZsecurityzdistributed.scheduler.preloadz"distributed.scheduler.preload-argv)Z	parameterZfile_dirargvzLocal Directory: %26szEnd scheduler at %r)-r   r   r   openwritestrr   getpidatexitregisterr   r   mkdirtempfileZmkdtempsysinsertplatform
startswithresourceZ	getrlimitZRLIMIT_NOFILEmaxZ	setrlimit
ValueErrorr   r   r   ZcurrentloggerinfoZdistributed.bokeh.schedulerr'   ImportErrorr   startdaskZconfiggetr   r
   closestopshutilZrmtree)ZhostZportZ
bokeh_portZshowr   Zbokeh_whitelistZbokeh_prefixZuse_xheadersr"   r*   Z	interfaceZlocal_directoryZpreloadr   r   Ztls_certZtls_keyZsecfr$   Zlocal_directory_createdr8   ZsoftZhardlimitZaddrr(   r)   r'   errorZ	schedulerr!   )r"   r#   main   s|    )




$


rG   c               C   s   t   t  d S )N)r	   rG   r!   r!   r!   r#   go   s    rH   __main__)-Z
__future__r   r   r   r0   r?   Zloggingr   rC   r4   r3   ZclickZtornado.ioloopr   Zdistributedr   Zdistributed.securityr   Zdistributed.utilsr   Zdistributed.cli.utilsr	   r
   r   Zdistributed.preloadingr   r   Zdistributed.proctitler   r   Z	getLoggerr;   ZPathZpem_file_option_typeZcommanddictZoptionr.   intboolZargumentZUNPROCESSEDrG   rH   __name__r!   r!   r!   r#   <module>   sj   











6[
