a
    ø£Beû  ã                   @   s\   d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZ G dd	„ d	eeeƒZdS )
z7A lab app that runs a sub process for a demo or a test.é    N)ÚExtensionAppÚExtensionAppJinjaMixin)ÚIOLoopé   )Ú	LabConfigÚadd_handlers)ÚProcessc                   @   s@   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dS )Ú
ProcessAppzFA jupyterlab app that runs a separate process and exits on completion.TFc                 C   s   t jdgi fS )zeGet the command and kwargs to run with `Process`.
        This is intended to be overridden.
        z	--version)ÚsysÚ
executable©Úself© r   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyterlab_server/process_app.pyÚget_command   s    zProcessApp.get_commandc                 C   s   t  ¡  | j¡ dS )zStart the application.N)r   ÚcurrentZadd_callbackÚ_run_commandr   r   r   r   Úinitialize_settings   s    zProcessApp.initialize_settingsc                 C   s   t | j| ƒ dS )zInitialize the handlers.N)r   Úhandlersr   r   r   r   Úinitialize_handlers    s    zProcessApp.initialize_handlersc                 C   sD   |   ¡ \}}| d| j¡ t|fi |¤Ž ¡ }t ¡  || j¡ d S )NÚlogger)	r   Ú
setdefaultÚlogr   Z
wait_asyncr   r   Z
add_futureÚ_process_finished)r   ÚcommandÚkwargsÚfuturer   r   r   r   $   s    zProcessApp._run_commandc              
   C   sb   zt  ¡  ¡  t | ¡ ¡ W n> ty\ } z&| j t	|ƒ¡ t d¡ W Y d }~n
d }~0 0 d S )Nr   )
r   r   Ústopr
   ÚexitÚresultÚ	Exceptionr   ÚerrorÚstr)r   r   Úer   r   r   r   *   s    zProcessApp._process_finishedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zload_other_extensionsZopen_browserr   r   r   r   r   r   r   r   r   r	      s   r	   )r'   r
   Z$jupyter_server.extension.applicationr   r   Ztornado.ioloopr   r   r   r   Úprocessr   r	   r   r   r   r   Ú<module>   s   