@@ -0,0 +1,3157 @@
+# neromum.py%0A#%0A# python3.5 neromum.py python3.5 sleep.py 20 0.5%0A%0Aimport sys%0Aimport socket%0Aimport os%0Aimport pickle%0A%0Afrom core import Logger%0A%0A%0Aclass Neromum(object):%0A%0A    def __init__(self):%0A        self.sock = None%0A        self.experiment = ' '.join(sys.argv%5B1:%5D)%0A        self.logger = Logger('MUM')%0A%0A    def run(self):%0A        self.logger.log('Creating the socket')%0A        self.initialize_socket()%0A        self.start_nerokid()%0A        self.listen_loop()%0A        logger.log('Shutting down')%0A        sock.shutdown(socket.SHUT_RDWR)%0A%0A    def initialize_socket(self):%0A        self.sock = socket.socket()%0A        self.sock.settimeout(5.0)%0A        # Bind the socket to localhost, auto choose port%0A        self.sock.bind(('localhost', 0))%0A        # Put the socket into server mode%0A        self.sock.listen(1)%0A        # Retrieve socket specs%0A        self.host, self.port = self.sock.getsockname()%0A%0A    def save_to_file(self, data, file):%0A        pass%0A%0A    def start_nerokid(self):%0A        self.logger.log('Launching kids')%0A        os.system('python3.5 nerokid.py %25s %25d %25s &' %25 (self.host, self.port, self.experiment))%0A%0A    def send_data_to_neroman(self):%0A        pass%0A%0A    def start_file_transfer(self):%0A        pass%0A%0A    def kill_child(self):%0A        pass%0A%0A    def ask_slurm_for_free_node(self):%0A        pass%0A%0A    #yup, evrything below needs complete rewrite.%0A    def get_nerokid_connection(self):%0A        self.logger.log('Waiting for kid connection...')%0A        try:%0A            self.kid_con, (khost, kport) = self.sock.accept()%0A        except socket.timeout:%0A            self.logger.log('- receive timeout...')%0A            return False%0A        return True%0A%0A    def get_data_from_nerokid(self):%0A        # wait for a connection%0A%0A        # Receive the data in small chunks and retransmit it%0A        self.data = b''%0A        while True:%0A            chunk = self.kid_con.recv(4096)  # 16, 4096%0A            if chunk:%0A                self.data += chunk%0A            else:%0A                break%0A        # Clean up the connection%0A        self.kid_con.close()%0A%0A    def parse_nerokid_data(self):%0A        if self.data:%0A            self.data = pickle.loads(self.data)%0A            if type(self.data) == dict:%0A                if 'log_output' in self.data:%0A                    for log_path, new_text in self.data%5B'log_output'%5D.items():%0A                        self.logger.log('New output in %25s:' %25 (log_path))%0A                        for ln in new_text.split('%5Cn'):%0A                            if not ln:%0A                                continue%0A                            self.logger.log('    %25s' %25 (ln.strip()))%0A                elif 'state' in self.data:%0A                    if self.data%5B'state'%5D == 'STARTED':%0A                        self.logger.log('Kid has started!')%0A                    elif self.data%5B'state'%5D == 'FINISHED':%0A                        self.logger.log('Kid has finished!')%0A                        return%0A%0A    def listen_loop(self):%0A        while True:%0A            if(self.get_nerokid_connection()):%0A                self.get_data_from_nerokid()%0A            # Process data%0A            self.parse_nerokid_data()%0A%0A%0A%0Aif __name__ == '__main__':%0A    Neromum().run()

rewrote neromum