if not choices: sys.stderr.write('WARNING: ' + command + ' not possible; skipping\n') return None return random.choice(choices) if __name__ == '__main__': ref = ProcDReference('INIT') next_proc = 0 while True: line = sys.stdin.readline() if not line: break line = line.rstrip() if line == 'SPAWN': parent = random_choice(line, ref.get_all_procs()) if not parent: continue child = 'P' + str(next_proc) next_proc += 1 sys.stdout.write('SPAWN ' + child + ' ' + parent + '\n') ref.spawn(child, parent) elif line == 'KILL': procs = ref.get_all_procs() procs.remove('INIT') victim = random_choice(line, procs) if not victim: continue sys.stdout.write('KILL ' + victim + '\n') ref.kill(victim) elif line == 'REGISTER':
sys.stderr.write('WARNING: ' + command + ' not possible; skipping\n') return None return random.choice(choices) if __name__ == '__main__': ref = ProcDReference('INIT') next_proc = 0 while True: line = sys.stdin.readline() if not line: break line = line.rstrip() if line == 'SPAWN': parent = random_choice(line, ref.get_all_procs()) if not parent: continue child = 'P' + str(next_proc) next_proc += 1 sys.stdout.write('SPAWN ' + child + ' ' + parent + '\n') ref.spawn(child, parent) elif line == 'KILL': procs = ref.get_all_procs() procs.remove('INIT') victim = random_choice(line, procs) if not victim: continue sys.stdout.write('KILL ' + victim + '\n') ref.kill(victim) elif line == 'REGISTER':