#import render from process import DelayProcess, MoveProcess, ProcessList import time sg = Node() canvas = Canvas(100, 20, sg, char='X') bomberman = Drawable('!', sg) sg.add_child(bomberman) bomberman.move(10, 10) bomb = Drawable('@', bomberman) sg.add_child(bomb) bomb.move(1, 0) #rt = render.RenderThread(canvas) #rt.start() processes = ProcessList() delay = DelayProcess(5) move = MoveProcess(bomberman, (7,2), 3) move_bomb = MoveProcess(bomb, (10,0), 2) #explosion = BoomProcess(bomb) delay.add_child(move) move.add_child(move_bomb) processes.attach_process(delay) start = time.time() while len(processes) > 0: now = time.time() delta = now-start processes.update_processes(delta)
def main(logger, config, xjobids=[]): # If not enabled, return immediately if not config.enabled: logger.info('prologue is disabled: doing nothing') return 0 pbs_home = config.pbs_home if not os.path.exists(pbs_home) or not os.path.isdir(pbs_home): raise ValueError('bad PBS_HOME directory: %s' % pbs_home) jobsdir = os.path.join(pbs_home, 'mom_priv', 'jobs') if not os.path.exists(jobsdir) or not os.path.isdir(jobsdir): raise ValueError('bad jobs directory: %s' % jobsdir) # Get process information before getting current job information procs = ProcessList() # Determine what users are currently running jobs on this node legalusers = nodeusers(logger, jobsdir, xjobids) # Combine safeusers with legalusers exemptusers = legalusers | config.safeusers # Set of additional processes not to kill apids = procs.ancestors(os.getpid()) bpids = procs.descendants(os.getpid()) exemptpids = apids | bpids # Create a dictionary that maps "top pids" to lists of process IDs # under that pid toplevel = {} for pid, pinfo in procs.items(): if pinfo['user'] not in exemptusers and \ pinfo['uid'] > SYSTHRESHOLD and \ pid not in exemptpids: tpid = procs.toppid(pid) toplevel.setdefault(tpid, []).append(pid) # Only print this warning message once if len(toplevel) > 0: logger.warning('rogue processes detected on ' + NODE) # Log the top level commands associated with rogue processes for tpid, pids in toplevel.items(): tproc = procs[tpid] pproc = procs[tproc['ppid']] pidstr = ' '.join([str(pid) for pid in pids]) logger.warning('rogue user: %s' % tproc['user']) logger.warning(' pids: %s' % pidstr) logger.info(' comm: %s -> %s' % \ (pproc['comm'], tproc['comm'])) # Display environment information for each process in the group for pid in pids: tenv = getenviron(logger, pid) tjobid = tenv.get('PBS_JOBID', '') ompi_size = tenv.get('OMPI_COMM_WORLD_SIZE', '') # Log more information from the environment if possible if tenv: logger.info(' %d: PBS_JOBID: %s; OMPI_COMM_WORLD_SIZE: %s' % \ (pid, tjobid, ompi_size)) # Kill the rogue processes if requested if config.kill: killprocs(logger, pids) return 0