From 17d5b3a7bc68594e5c5a8f8be5d68b140605ff8d Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 20 Mar 2015 19:19:49 -0600 Subject: [PATCH] Remove unnecessary locks. --- .../modules/dynamips/dynamips_hypervisor.py | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/modules/dynamips/dynamips_hypervisor.py index 8a0d296f..2b0401d7 100644 --- a/gns3server/modules/dynamips/dynamips_hypervisor.py +++ b/gns3server/modules/dynamips/dynamips_hypervisor.py @@ -58,7 +58,6 @@ class DynamipsHypervisor: self._uuid = None self._reader = None self._writer = None - self._io_lock = asyncio.Lock() @asyncio.coroutine @@ -82,8 +81,7 @@ class DynamipsHypervisor: while time.time() - begin < timeout: yield from asyncio.sleep(0.01) try: - with (yield from self._io_lock): - self._reader, self._writer = yield from asyncio.open_connection(host, self._port) + self._reader, self._writer = yield from asyncio.open_connection(host, self._port) except OSError as e: last_exception = e continue @@ -123,9 +121,8 @@ class DynamipsHypervisor: """ yield from self.send("hypervisor close") - with (yield from self._io_lock): - self._writer.close() - self._reader, self._writer = None + self._writer.close() + self._reader, self._writer = None @asyncio.coroutine def stop(self): @@ -133,18 +130,17 @@ class DynamipsHypervisor: Stops this hypervisor (will no longer run). """ - with (yield from self._io_lock): - try: - # try to properly stop the hypervisor - yield from self.send("hypervisor stop") - except DynamipsError: - pass - try: - yield from self._writer.drain() - self._writer.close() - except OSError as e: - log.debug("Stopping hypervisor {}:{} {}".format(self._host, self._port, e)) - self._reader = self._writer = None + try: + # try to properly stop the hypervisor + yield from self.send("hypervisor stop") + except DynamipsError: + pass + try: + yield from self._writer.drain() + self._writer.close() + except OSError as e: + log.debug("Stopping hypervisor {}:{} {}".format(self._host, self._port, e)) + self._reader = self._writer = None @asyncio.coroutine def reset(self): @@ -283,7 +279,7 @@ class DynamipsHypervisor: .format(host=self._host, port=self._port, run=self.is_running())) buf += chunk.decode() except OSError as e: - raise DynamipsError("Communication timed out with {host}:{port} :{error}, Dynamips process running: {run}" + 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())) # If the buffer doesn't end in '\n' then we can't be done