title: How to check if a slurm job is the last **RUNNING** in an array?
body: <p>I need to send an array of jobs to a SLURM cluster, and I need them to aggregate a part of their results in one combined file. However, I can't have multiple independent slurm array drones writing to the same file. So currently I'm trying to make it so that only the last drone aggregates all the data.</p>
  
  <p>At the moment, I have each array drone check if all the other results are written when it finishes, and if they are, then it does the file writing. However, currently multiple drones finish in almost the same time, and seem to still try to write to the same file.</p>
  
  <p>I would like to make it so that only the last drone in the array does this. However the last drone numerically (i.e by checking the JOBID) may not be the last drone to finish, as the jobs take slightly variable lengths of time.</p>
  
  <p>So is there a way for each drone to check that it's the last one running in the array or something? Or is there a better way to do this that I'm overlooking?</p>
  
  <p>Also, I would prefer answer in <code>python</code> since that's what I'm using, if possible.</p>