1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Merge pull request #104 from GNS3/dynamips_hypervisor_lock

Asyncio lock for Dynamips hypervisor.
This commit is contained in:
Jeremy Grossmann 2015-03-21 00:24:54 +00:00
commit 5b08677537

View File

@ -59,6 +59,8 @@ class DynamipsHypervisor:
self._reader = None
self._writer = None
self._io_lock = asyncio.Lock()
@asyncio.coroutine
def connect(self, timeout=10):
"""
@ -80,6 +82,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)
except OSError as e:
last_exception = e
@ -120,6 +123,7 @@ class DynamipsHypervisor:
"""
yield from self.send("hypervisor close")
with (yield from self._io_lock):
self._writer.close()
self._reader, self._writer = None
@ -129,6 +133,7 @@ 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")
@ -255,6 +260,7 @@ class DynamipsHypervisor:
# but still have more data. The only thing we know for sure is the last line
# will begin with '100-' or a '2xx-' and end with '\r\n'
with (yield from self._io_lock):
if self._writer is None or self._reader is None:
raise DynamipsError("Not connected")