o
    wi                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	 ddl
mZmZmZmZ ddlmZ ddlmZmZ G dd	 d	eZG d
d deZG dd dee ZG dd deZdS )    N)Path)DictListOptionalUnion   )ExecutorInfoWatcherJobR)JobEnvironment)DelayedSubmissionUncompletedJobErrorc                   @   s   e Zd ZdeddfddZdS )DebugInfoWatcherjob_idreturnNc                 C      d S N )selfr   r   r   Q/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/submitit/local/debug.pyregister_job      zDebugInfoWatcher.register_job)__name__
__module____qualname__strr   r   r   r   r   r      s    r   c                   @   s>   e Zd ZdddddddZdefddZdeddfd	d
ZdS )DebugJobEnvironmentSUBMITIT_DEBUG_JOB_IDSUBMITIT_DEBUG_NOT_SET)r   	num_nodes	num_tasksnodeglobal_rank
local_rankr   c                 C   s
   dt jv S )Nr   )osenvironr   r   r   r   	activated#      
zDebugJobEnvironment.activated	countdownNc                 C   r   r   r   )r   r*   r   r   r   _requeue&   r   zDebugJobEnvironment._requeue)r   r   r   _envboolr(   intr+   r   r   r   r   r      s    
r   c                       s   e Zd Ze Zdededdf fddZdefddZe	de
fd	d
Zd#deddfddZd$ddZdee fddZdee fddZd$ddZd%dedefddZe	defddZd&dedeeef fdd Zd$d!d"Z  ZS )'DebugJobfolder
submissionr   Nc                    sF   dt | }t j||d || _d| _ttj| _| j| jd< d S )NDEBUG_)r0   r   Fr   )	idsuper__init___submission	cancelleddictr%   r&   r   )r   r0   r1   r   	__class__r   r   r5   -   s   zDebugJob.__init__c                 C   s   | j S r   )r6   r'   r   r   r   r1   5   s   zDebugJob.submissionc                 C   s   dS )N   r   r'   r   r   r   r!   8      zDebugJob.num_tasksTcheckc                 C   s
   d| _ d S )NT)r7   )r   r=   r   r   r   cancel<   r)   zDebugJob.cancelc                 C   s   | j rtd|  dd S )NzJob z was cancelled.)r7   r   r'   r   r   r   _check_not_cancelled?   s   zDebugJob._check_not_cancelledc              
   C   s|  |    | j r| jjgS ttj}tj  tj| j t	
d}| jjjjddd t	| jj}|t	j t	| jj}|t	j || || |d| jj d zJz| j gW W tj  tj| || || S  ty } z t| tjdddrdd l}|   dd l}|   d }~ww tj  tj| || || w )	N T)exist_okparentsz0Logging is written both to stderr/stdout and to z8/err. But call to print will only appear in the console.PYTHONBREAKPOINTipdbr   )r?   r6   done_resultr8   r%   r&   clearupdatelogging	getLoggerpathsstdoutparentmkdirFileHandlersetLevelDEBUGstderrWARNING
addHandlerwarningresultremoveHandler	Exceptionprintget
startswithrD   post_mortempdb)r   environ_backuproot_loggerstdout_handlerstderr_handlererD   r]   r   r   r   resultsC   sL   










zDebugJob.resultsc              
   C   sB   |    z| j  W d S  ty  } z|W  Y d }~S d }~ww r   )r?   r6   rV   rX   )r   rb   r   r   r   	exceptionn   s   
zDebugJob.exceptionc                 C   s   |    d S r   )rc   r'   r   r   r   waitx   s   zDebugJob.waitFforce_checkc                 C   s   |    | j S r   )rc   r6   rE   )r   rf   r   r   r   rE   |   s   
zDebugJob.donec                 C   s   | j  rdS | jrdS dS )NDONE	CANCELLEDQUEUED)r6   rE   r7   r'   r   r   r   state   s
   
zDebugJob.stateforcemodec                 C   s
   d| j iS )NSTATE)rj   )r   rl   r   r   r   get_info   r)   zDebugJob.get_infoc                 C   r   r   r   r'   r   r   r   __del__   r<   zDebugJob.__del__)T)r   N)F)rk   )r   r   r   r   watcherr   r   r5   r1   propertyr.   r!   r-   r>   r?   r   r   rc   r   BaseExceptionrd   re   rE   r   rj   r   rn   ro   __classcell__r   r   r9   r   r/   *   s     
+

r/   c                       sR   e Zd ZeZdeeef f fddZde	j
e de	j
ee	j  fddZ  ZS )DebugExecutorr0   c                    s   t  | d S r   )r4   r5   )r   r0   r9   r   r   r5      s   zDebugExecutor.__init__delayed_submissionsr   c                    s    fdd|D S )Nc                    s   g | ]}t  j|qS r   )r/   r0   ).0dsr'   r   r   
<listcomp>   s    z?DebugExecutor._internal_process_submissions.<locals>.<listcomp>r   )r   ru   r   r'   r   _internal_process_submissions   s   z+DebugExecutor._internal_process_submissions)r   r   r   r/   	job_classr   r   r   r5   tpr   r   r
   Anyry   rs   r   r   r9   r   rt      s    rt   )rI   r%   typingr{   pathlibr   r   r   r   r   	core.corer   r	   r
   r   core.job_environmentr   
core.utilsr   r   r   r   r/   rt   r   r   r   r   <module>   s   g