Address deprecated warnings with Python 3.8

All these chances work fine with 3.5, our minimally required version.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka
2020-01-09 11:40:24 +01:00
parent e383e16570
commit 6a67d69411
3 changed files with 24 additions and 28 deletions

View File

@@ -63,14 +63,13 @@ class LogOutput:
self.stderr.append(line)
@asyncio.coroutine
def _read_stream(stream, callback):
async def _read_stream(stream, callback):
"""
This asynchronous method reads from the output stream of the
application and transfers each line to the callback function.
"""
while True:
line = yield from stream.readline()
line = await stream.readline()
try:
line = line.decode('utf-8')
except UnicodeDecodeError as err:
@@ -82,8 +81,7 @@ def _read_stream(stream, callback):
break
@asyncio.coroutine
def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
async def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
"""
Run a command asynchronously.
"""
@@ -95,7 +93,7 @@ def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
logo = LogOutput(liveupdate)
try:
process = yield from asyncio.create_subprocess_exec(
process = await asyncio.create_subprocess_exec(
*cmd,
cwd=cwd,
env=env,
@@ -110,11 +108,11 @@ def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
raise ex
return (errno.EPERM, str(ex))
yield from asyncio.wait([
await asyncio.wait([
_read_stream(process.stdout, logo.log_stdout),
_read_stream(process.stderr, logo.log_stderr)
])
ret = yield from process.wait()
ret = await process.wait()
if ret and fail:
msg = 'Command "{cwd}$ {cmd}" failed'.format(cwd=cwd, cmd=cmdstr)