From ee8362d89aa55b0efb1328bc8d5426ccc1e99e26 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 28 Mar 2015 19:23:01 -0600 Subject: [PATCH] Fixes issue when asyncio read is cancelled and data is still sent by Dynamips hypervisor. Fixes #113. --- gns3server/modules/dynamips/dynamips_hypervisor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/modules/dynamips/dynamips_hypervisor.py index 60a24b19..2f6de303 100644 --- a/gns3server/modules/dynamips/dynamips_hypervisor.py +++ b/gns3server/modules/dynamips/dynamips_hypervisor.py @@ -265,6 +265,7 @@ class DynamipsHypervisor: command = command.strip() + '\n' log.debug("sending {}".format(command)) self._writer.write(command.encode()) + yield from self._writer.drain() except OSError as e: raise DynamipsError("Lost communication with {host}:{port} :{error}, Dynamips process running: {run}" .format(host=self._host, port=self._port, error=e, run=self.is_running())) @@ -274,11 +275,16 @@ class DynamipsHypervisor: buf = '' while True: try: - chunk = yield from self._reader.read(1024) # match to Dynamips' buffer size - if not chunk: + try: + line = yield from self._reader.readline() + except asyncio.CancelledError: + # task has been canceled but continue to read + # any remaining data sent by the hypervisor + continue + if not line: raise DynamipsError("No data returned from {host}:{port}, Dynamips process running: {run}" .format(host=self._host, port=self._port, run=self.is_running())) - buf += chunk.decode() + buf += line.decode() except OSError as e: raise DynamipsError("Lost communication with {host}:{port} :{error}, Dynamips process running: {run}" .format(host=self._host, port=self._port, error=e, run=self.is_running()))