From a8e4e27a851a2042bc13a6663affd599edd7b7cb Mon Sep 17 00:00:00 2001 From: Isaacwhyuenac <13378284+Isaacwhyuenac@users.noreply.github.com> Date: Wed, 28 Jul 2021 17:49:37 +0800 Subject: [PATCH] Update asyncio_subprocess_protocol.py Fix the asyncio_subprocess_protocol.py. The result will now align with asyncio_subprocess_coroutine.py. --- source/asyncio/asyncio_subprocess_protocol.py | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/source/asyncio/asyncio_subprocess_protocol.py b/source/asyncio/asyncio_subprocess_protocol.py index 2aab995b..ebf852e6 100644 --- a/source/asyncio/asyncio_subprocess_protocol.py +++ b/source/asyncio/asyncio_subprocess_protocol.py @@ -33,29 +33,25 @@ def process_exited(self): print('process exited') return_code = self.transport.get_returncode() print('return code {}'.format(return_code)) - if not return_code: - cmd_output = bytes(self.buffer).decode() - results = self._parse_results(cmd_output) - else: - results = [] - self.done.set_result((return_code, results)) - - def _parse_results(self, output): - print('parsing results') - # Output has one row of headers, all single words. The - # remaining rows are one per filesystem, with columns - # matching the headers (assuming that none of the - # mount points have whitespace in the names). - if not output: - return [] - lines = output.splitlines() - headers = lines[0].split() - devices = lines[1:] - results = [ - dict(zip(headers, line.split())) - for line in devices - ] - return results + + self.done.set_result(return_code) + +def _parse_results(output): + print('parsing results') + # Output has one row of headers, all single words. The + # remaining rows are one per filesystem, with columns + # matching the headers (assuming that none of the + # mount points have whitespace in the names). + if not output: + return [] + lines = output.splitlines() + headers = lines[0].split() + devices = lines[1:] + results = [ + dict(zip(headers, line.split())) + for line in devices + ] + return results async def run_df(loop): @@ -77,7 +73,7 @@ async def run_df(loop): finally: transport.close() - return cmd_done.result() + return cmd_done.result(), _parse_results(bytes(protocol.buffer).decode()) event_loop = asyncio.get_event_loop()