diff --git a/src/communication.py b/src/communication.py index 3b85478..f42083c 100644 --- a/src/communication.py +++ b/src/communication.py @@ -48,7 +48,7 @@ class ClusterCommunicationModule(): # send docker swarm token to the worker token = self.node_manager.docker_client.swarm.attrs['JoinTokens']['Worker'] - conn.send(f'[DOCKER_TOKEN] {token}'.encode()) + conn.send(f'[DOCKER_TOKEN] {token}'.encode()) print(f"Send token: {token} to the worker.") print("Please Enter to continue...") @@ -65,7 +65,7 @@ class ClusterCommunicationModule(): self.client_sock.send('[CHECK]'.encode()) # join docker swarm cluster - token = self.client_sock.recv(1024).decode().split()[-1] + token = self.client_sock.recv(1024).decode().split(' ')[-1] print("Receive Docker Swarm Join_Token=", token) status = self.node_manager.docker_client.swarm.join(remote_addrs=[f'{addr[0]}:2377'], join_token=token) @@ -84,14 +84,14 @@ class ClusterCommunicationModule(): return False def handle_command(self, data): - command, args = data.split() + command, args = data.split(' ') if command == '[INFO]': data = {'host': self.host, 'GPU': self.node_manager.GPU, 'GPU_num': self.node_manager.GPU_num} self.client_sock.send(json.dumps(data).encode()) elif command == '[STOP]': self.node_manager.docker_client.swarm.leave() data = {'host': self.host} - self.client_sock.send(f'[STOP_CHECK] {json.dumps(data)}'.encode()) + self.client_sock.send(f'[STOP_CHECK] {json.dumps(data)}'.encode()) return True @@ -119,7 +119,7 @@ class ClusterCommunicationModule(): ans = [] for conn in self.worker_conns: try: - conn.send('[INFO] {}'.encode()) + conn.send('[INFO] {}'.encode()) data = conn.recv(1024) data = json.loads(data.decode()) ans.append(data) @@ -131,8 +131,8 @@ class ClusterCommunicationModule(): def exit(self): if self.node_manager.status == 'master': for conn in self.worker_conns: - conn.send('[STOP] {}'.encode()) - check, args = conn.recv(1024).decode().split() + conn.send('[STOP] {}'.encode()) + check, args = conn.recv(1024).decode().split(' ') print(f'{args} has stopped.') self.node_manager.docker_client.swarm.leave(force=True)