async def receiver(self): """This task waits for Lean responses, updating the server state (tasks and messages) and triggering events when a response comes.""" if not self.process: raise ValueError('No Lean server') unfinished_message = b'' async for data in self.process.stdout: lines = (unfinished_message + data).split(b'\n') unfinished_message = lines.pop( ) # usually empty, but can be half a message for line in lines: if self.debug_bytes: print(f'Received {line}') resp = parse_response(line.decode()) if self.debug: print(f'Received {resp}') if isinstance(resp, CurrentTasksResponse): self.current_tasks = resp.tasks if not resp.is_running: self.is_fully_ready.set() elif isinstance(resp, AllMessagesResponse): self.messages = resp.msgs if hasattr(resp, 'seq_num'): self.responses[resp.seq_num] = resp self.response_events[resp.seq_num].set()
def lean_reply(self): """Called when Lean outputs something.""" data = self.process.readAllStandardOutput().data().decode() for line in data.strip().split('\n'): resp = parse_response(line) if isinstance(resp, InfoResponse): self.goal_state = resp.record.state self.state_update.emit() elif isinstance(resp, CurrentTasksResponse): self.current_tasks = resp.tasks if self.is_busy and not resp.is_running: self.is_ready.emit() self.is_busy = resp.is_running elif isinstance(resp, AllMessagesResponse): self.messages = resp.msgs for msg in resp.msgs: if msg.severity == Severity.error: self.error.emit(msg.text) self.incoming_message.emit()
async def receiver(self): """This task waits for Lean responses, updating the server state (tasks and messages) and triggering events when a response comes.""" if not self.process: raise ValueError('No Lean server') async for data in self.process.stdout: for line in data.decode().strip().split('\n'): resp = parse_response(line) if self.debug: print(f'Received {resp}') if isinstance(resp, CurrentTasksResponse): self.current_tasks = resp.tasks if not resp.is_running: self.is_fully_ready.set() elif isinstance(resp, AllMessagesResponse): self.messages = resp.msgs if hasattr(resp, 'seq_num'): self.responses[resp.seq_num] = resp self.response_events[resp.seq_num].set()