Replace asyncio.async with ensure_future because of deprecation, Fixes: #1269

This commit is contained in:
ziajka committed 2018-01-24 11:11:53 +01:00
1 parent 838d82a98b
commit d9a0ec9ff3
36 files changed
+192 -192

No files matched your search

+1 -1
View File
@@ -127,7 +127,7 @@ class BaseManager:
tasks = []
for node_id in self._nodes.keys():
tasks.append(asyncio.async(self.close_node(node_id)))
tasks.append(asyncio.ensure_future(self.close_node(node_id)))
if tasks:
done, _ = yield from asyncio.wait(tasks)
+1 -1
View File
@@ -511,7 +511,7 @@ class DockerVM(BaseNode):
output_stream.feed_data(self.name.encode() + b" console is now available... Press RETURN to get started.\r\n")
asyncio.async(self._read_console_output(self._console_websocket, output_stream))
asyncio.ensure_future(self._read_console_output(self._console_websocket, output_stream))
@asyncio.coroutine
def _read_console_output(self, ws, out):
+2 -2
View File
@@ -172,7 +172,7 @@ class Dynamips(BaseManager):
tasks = []
for device in self._devices.values():
tasks.append(asyncio.async(device.hypervisor.stop()))
tasks.append(asyncio.ensure_future(device.hypervisor.stop()))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@@ -196,7 +196,7 @@ class Dynamips(BaseManager):
tasks = []
for device in self._devices.values():
if device.project.id == project.id:
tasks.append(asyncio.async(device.delete()))
tasks.append(asyncio.ensure_future(device.delete()))
if tasks:
done, _ = yield from asyncio.wait(tasks)
+1 -1
View File
@@ -194,7 +194,7 @@ class Router(BaseNode):
"""
Called when the NVRAM file has changed
"""
asyncio.async(self.save_configs())
asyncio.ensure_future(self.save_configs())
@property
def dynamips_id(self):
+1 -1
View File
@@ -325,7 +325,7 @@ class Project:
tasks = []
for node in self._nodes:
tasks.append(asyncio.async(node.manager.close_node(node.id)))
tasks.append(asyncio.ensure_future(node.manager.close_node(node.id)))
if tasks:
done, _ = yield from asyncio.wait(tasks)
+1 -1
View File
@@ -738,4 +738,4 @@ if __name__ == '__main__':
loop = asyncio.get_event_loop()
vmware = VMware.instance()
print("=> Check version")
loop.run_until_complete(asyncio.async(vmware.check_vmware_version()))
loop.run_until_complete(asyncio.ensure_future(vmware.check_vmware_version()))
+2 -2
View File
@@ -415,7 +415,7 @@ class Compute:
if self._connection_failure == 5:
log.warning("Cannot connect to compute '{}': {}".format(self._id, e))
yield from self._controller.close_compute_projects(self)
asyncio.get_event_loop().call_later(2, lambda: asyncio.async(self._try_reconnect()))
asyncio.get_event_loop().call_later(2, lambda: asyncio.ensure_future(self._try_reconnect()))
return
except aiohttp.web.HTTPNotFound:
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server or it's a 1.X server".format(self._id))
@@ -472,7 +472,7 @@ class Compute:
# Try to reconnect after 1 seconds if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
asyncio.get_event_loop().call_later(1, lambda: asyncio.async(self.connect()))
asyncio.get_event_loop().call_later(1, lambda: asyncio.ensure_future(self.connect()))
self._ws = None
self._cpu_usage_percent = None
self._memory_usage_percent = None
+1 -1
View File
@@ -302,7 +302,7 @@ class GNS3VM:
# check if the VM is in the same subnet as the local server, start 10 seconds later to give
# some time for the compute in the VM to be ready for requests
asyncio.get_event_loop().call_later(10, lambda: asyncio.async(self._check_network(compute)))
asyncio.get_event_loop().call_later(10, lambda: asyncio.ensure_future(self._check_network(compute)))
@asyncio.coroutine
def _check_network(self, compute):
+1 -1
View File
@@ -288,7 +288,7 @@ class Link:
self._capturing = True
self._capture_file_name = capture_file_name
self._streaming_pcap = asyncio.async(self._start_streaming_pcap())
self._streaming_pcap = asyncio.ensure_future(self._start_streaming_pcap())
self._project.controller.notification.emit("link.updated", self.__json__())
@asyncio.coroutine
+1 -1
View File
@@ -867,7 +867,7 @@ class Project:
# Start all in the background without waiting for completion
# we ignore errors because we want to let the user open
# their project and fix it
asyncio.async(self.start_all())
asyncio.ensure_future(self.start_all())
@asyncio.coroutine
def wait_loaded(self):
@@ -43,7 +43,7 @@ class NotificationHandler:
ws = WebSocketResponse()
yield from ws.prepare(request)
asyncio.async(process_websocket(ws))
asyncio.ensure_future(process_websocket(ws))
with notifications.queue() as queue:
while True:
@@ -246,7 +246,7 @@ class ProjectHandler:
ws = aiohttp.web.WebSocketResponse()
yield from ws.prepare(request)
asyncio.async(process_websocket(ws))
asyncio.ensure_future(process_websocket(ws))
with controller.notification.queue(project) as queue:
while True:
@@ -57,7 +57,7 @@ class ServerHandler:
tasks = []
for project in projects:
tasks.append(asyncio.async(project.close()))
tasks.append(asyncio.ensure_future(project.close()))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@@ -71,7 +71,7 @@ class ServerHandler:
# then shutdown the server itself
from gns3server.web.web_server import WebServer
server = WebServer.instance()
asyncio.async(server.shutdown_server())
asyncio.ensure_future(server.shutdown_server())
response.set_status(201)
@Route.get(
+3 -3
View File
@@ -223,9 +223,9 @@ def run():
if server_config.getboolean("local"):
log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem")
# we only support Python 3 version >= 3.4
if sys.version_info < (3, 4):
raise SystemExit("Python 3.4 or higher is required")
# we only support Python 3 version >= 3.4.4
if sys.version_info < (3, 4, 4):
raise SystemExit("Python 3.4.4 or higher is required")
user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
major=sys.version_info[0], minor=sys.version_info[1],
+1 -1
View File
@@ -108,7 +108,7 @@ def _check_process(process, termination_callback):
def monitor_process(process, termination_callback):
"""Call termination_callback when a process dies"""
asyncio.async(_check_process(process, termination_callback))
asyncio.ensure_future(_check_process(process, termination_callback))
@asyncio.coroutine
@@ -69,8 +69,8 @@ class AsyncioRawCommandServer:
else:
replaces.append((replace[0], replace[1], ))
network_read = asyncio.async(network_reader.read(READ_SIZE))
reader_read = asyncio.async(process_reader.read(READ_SIZE))
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
reader_read = asyncio.ensure_future(process_reader.read(READ_SIZE))
timeout = 30
while True:
@@ -89,7 +89,7 @@ class AsyncioRawCommandServer:
if network_reader.at_eof():
raise ConnectionResetError()
network_read = asyncio.async(network_reader.read(READ_SIZE))
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
process_writer.write(data)
yield from process_writer.drain()
@@ -97,7 +97,7 @@ class AsyncioRawCommandServer:
if process_reader.at_eof():
raise ConnectionResetError()
reader_read = asyncio.async(process_reader.read(READ_SIZE))
reader_read = asyncio.ensure_future(process_reader.read(READ_SIZE))
for replace in replaces:
data = data.replace(replace[0], replace[1])
+4 -4
View File
@@ -229,13 +229,13 @@ class AsyncioTelnetServer:
self._reader_process = network_reader
if self._reader:
if self._reader_process == network_reader:
self._current_read = asyncio.async(self._reader.read(READ_SIZE))
self._current_read = asyncio.ensure_future(self._reader.read(READ_SIZE))
return self._current_read
return None
@asyncio.coroutine
def _process(self, network_reader, network_writer, connection):
network_read = asyncio.async(network_reader.read(READ_SIZE))
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
reader_read = yield from self._get_reader(network_reader)
while True:
@@ -261,7 +261,7 @@ class AsyncioTelnetServer:
if network_reader.at_eof():
raise ConnectionResetError()
network_read = asyncio.async(network_reader.read(READ_SIZE))
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
if IAC in data:
data = yield from self._IAC_parser(data, network_reader, network_writer, connection)
@@ -418,7 +418,7 @@ if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
loop = asyncio.get_event_loop()
process = loop.run_until_complete(asyncio.async(asyncio.subprocess.create_subprocess_exec("/bin/sh", "-i",
process = loop.run_until_complete(asyncio.ensure_future(asyncio.subprocess.create_subprocess_exec("/bin/sh", "-i",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
stdin=asyncio.subprocess.PIPE)))
+3 -3
View File
@@ -136,7 +136,7 @@ class WebServer:
def signal_handler(signame, *args):
log.warning("Server has got signal {}, exiting...".format(signame))
asyncio.async(self.shutdown_server())
asyncio.ensure_future(self.shutdown_server())
signals = ["SIGTERM", "SIGINT"]
if sys.platform.startswith("win"):
@@ -203,7 +203,7 @@ class WebServer:
# Because with a large image collection
# without md5sum already computed we start the
# computing with server start
asyncio.async(Qemu.instance().list_images())
asyncio.ensure_future(Qemu.instance().list_images())
def run(self):
"""
@@ -283,7 +283,7 @@ class WebServer:
self._exit_handling()
if server_config.getboolean("shell"):
asyncio.async(self.start_shell())
asyncio.ensure_future(self.start_shell())
try:
self._loop.run_forever()