def clean_proc_dir(opts):
 for basefilename in os.listdir(salt.minion.get_proc_dir(opts['cachedir'])):
  fn_ = os.path.join(salt.minion.get_proc_dir(opts['cachedir']), basefilename)
  with salt.utils.fopen(fn_, 'rb') as fp_:
   job = None
   try:
    job = salt.payload.Serial(opts).load(fp_)
   except Exception:
    if salt.utils.is_windows():
     fp_.close()
    try:
     os.unlink(fn_)
     continue
    except OSError:
     continue
   log.debug('schedule.clean_proc_dir: checking job {0} for process existence'.format(job))
   if ((job is not None) and ('pid' in job)):
    if salt.utils.process.os_is_running(job['pid']):
     log.debug('schedule.clean_proc_dir: Cleaning proc dir, pid {0} still exists.'.format(job['pid']))
    else:
     if salt.utils.is_windows():
      fp_.close()
     try:
      os.unlink(fn_)
     except OSError:
      pass

def clean_proc_dir ( opts ) : for basefilename in os . listdir ( salt . minion . get_proc_dir ( opts [ 'cachedir' ] ) ) : fn_ = os . path . join ( salt . minion . get_proc_dir ( opts [ 'cachedir' ] ) , basefilename ) with salt . utils . fopen ( fn_ , 'rb' ) as fp_ : job = None try : job = salt . payload . Serial ( opts ) . load ( fp_ ) except Exception : if salt . utils . is_windows ( ) : fp_ . close ( ) try : os . unlink ( fn_ ) continue except OSError : continue log . debug ( 'schedule.clean_proc_dir: checking job {0} for process existence' . format ( job ) ) if ( ( job is not None ) and ( 'pid' in job ) ) : if salt . utils . process . os_is_running ( job [ 'pid' ] ) : log . debug ( 'schedule.clean_proc_dir: Cleaning proc dir, pid {0} still exists.' . format ( job [ 'pid' ] ) ) else : if salt . utils . is_windows ( ) : fp_ . close ( ) try : os . unlink ( fn_ ) except OSError : pass
loop through jid files in the minion proc directory and remove any that refer to processes that no longer exist .