def update_jobs(): global jobs, server command = ['jobsub_q'] if server != None: command.append('--jobsub-server=%s' % server) command.append('--group=%s' % project_utilities.get_experiment()) command.append('--user=%s' % project_utilities.get_user()) command.append('--role=%s' % project_utilities.get_role()) jobinfo = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) jobout, joberr = jobinfo.communicate() rc = jobinfo.poll() if rc != 0: #raise JobsubError(command, rc, jobout, joberr) # Simply return in case jobsub_q fails. return jobs = jobout.split('\n')
def kill_jobs(self): if self.current_project_def == None: tkinter_messagebox.showwarning('', 'No project selected.') return if self.current_stage_def == None: tkinter_messagebox.showwarning('', 'No stage selected.') return top = self.winfo_toplevel() old_cursor = top['cursor'] try: top['cursor'] = 'watch' top.update_idletasks() BatchStatus.update_jobs() jobs = BatchStatus.get_jobs() top['cursor'] = old_cursor except: top['cursor'] = old_cursor e = sys.exc_info() traceback.print_tb(e[2]) tkinter_messagebox.showerror('', e[1]) # Figure out which clusters to kill. cluster_ids = set() for job in jobs: words = job.split() if len(words) >= 2: jobid = words[0] script = words[-1] workscript = '%s-%s-%s.sh' % ( self.current_stage_def.name, self.current_project_def.name, self.current_project_def.release_tag) if script.find(workscript) == 0: cp_server = jobid.split('@') if len(cp_server) == 2: clusproc = cp_server[0] server = cp_server[1] cp = clusproc.split('.') if len(cp) == 2: cluster = cp[0] process = cp[1] cluster_id = '%s@%s' % (cluster, server) if not cluster_id in cluster_ids: cluster_ids.add(cluster_id) # Actually issue kill commands. for cluster_id in cluster_ids: print('Kill cluster id %s' % cluster_id) command = ['jobsub_rm'] if self.current_project_def.server != '-' and self.current_project_def.server != '': command.append('--jobsub-server=%s' % self.current_project_def.server) command.append('--jobid=%s' % cluster_id) command.append('--role=%s' % project_utilities.get_role()) jobinfo = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) jobout, joberr = jobinfo.communicate() jobout = convert_str(jobout) joberr = convert_str(joberr) rc = jobinfo.poll() if rc != 0: raise JobsubError(command, rc, jobout, joberr) self.update_jobs()