o
    rri&
                     @   s   d dl mZ d dlmZ d dlZd dlm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mZ dd
lmZ eedZdde	je dedefddZdefddZdS )    )	ExitStack)partialN)rmtree   )git_save)start_ddp_workers)DecoratedMain)disable_logging
simple_logred)ShepherdzLaunch:Fargvmainclearc                 C   s   t |t}|| }|jdurE|  | sE|j}ttd|j d|j d |r?td |	|j |
  td nttd |ri|jj rktd z	t|jj W dS  tyh   td	 Y dS w dS dS )
z{This will check if an existing job is running and warn,
    unless --clear is passed, in which case we must cancel it.
    NzFound existing slurm job z with status .zCancelling the existing job.   z4PLEASE ABORT NOW UNLESS YOU ARE SURE OF WHAT YOU DO.zRemoving existing XP folder.z>Failed to properly remove folder, but things should be okay...)r   logget_sheep_from_argvjobupdateis_doner   job_idstatecancel_lazycommittimesleepxpfolderexistsr   OSError)r   r   r   shepherdsheepr    r#   </home/ubuntu/.local/lib/python3.10/site-packages/dora/run.pycheck_job_and_clear   s*   


r%   c                 C   s*  | | j}t }| jr<dtjvr<dtjd< t|}t|| |t	| t
tjtjddgtjdd    | jrVtjdsVt| j|| j t|| j| j n-dtjvrmt| j|| j dtjd< dtjd< | jtjdd < t  |  W d    d S W d    d S 1 sw   Y  d S )	N_DORA_GIT_SAVE_DONE1z-mdorar   RANK
WORLD_SIZE0)get_xpr   r   r   osenvironget_new_cloneassign_cloneenter_contextenter_cloneexecvsys
executableddpgetr%   r   r   ddp_workersr	   )argsr   r   stackcloner#   r#   r$   
run_action2   s*   

$


	"r<   )F)
contextlibr   	functoolsr   r-   shutilr   r4   typingtpr    r   executorr   r   r   r   r	   r
   r   shepr   Liststrboolr%   r<   r#   r#   r#   r$   <module>   s   
