From 9ec86f3c415a963431d8ccbf60d0d1544542f231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 26 Feb 2020 05:38:59 +0100 Subject: [PATCH] Workaround different behaviour of asyncio's Process.communicate() In asyncio's Process.communicate() input=None does not close stdin. Workaround it by using b'' instead of None. https://bugs.python.org/issue39744 --- qubes/tests/extra.py | 2 ++ qubes/tests/vm/qubesvm.py | 4 ++-- qubes/vm/qubesvm.py | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qubes/tests/extra.py b/qubes/tests/extra.py index a1e0f03e..91a26495 100644 --- a/qubes/tests/extra.py +++ b/qubes/tests/extra.py @@ -42,6 +42,8 @@ class ProcessWrapper(object): return setattr(self._proc, key, value) def communicate(self, input=None): + if self._proc.stdin is not None and input is None: + input = b'' return self._loop.run_until_complete(self._proc.communicate(input)) def wait(self): diff --git a/qubes/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py index 2f27cb13..6f0a8319 100644 --- a/qubes/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -2017,7 +2017,7 @@ class TC_90_QubesVM(QubesVMTestsMixin, qubes.tests.QubesTestCase): stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - communicate_mock.assert_called_once_with(input=None) + communicate_mock.assert_called_once_with(input=b'') self.assertEqual(value, (b'stdout', b'stderr')) func_mock.reset_mock() @@ -2045,7 +2045,7 @@ class TC_90_QubesVM(QubesVMTestsMixin, qubes.tests.QubesTestCase): stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - communicate_mock.assert_called_once_with(input=None) + communicate_mock.assert_called_once_with(input=b'') self.assertEqual(exc.exception.returncode, 1) self.assertEqual(exc.exception.output, b'stdout') self.assertEqual(exc.exception.stderr, b'stderr') diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 3ed3aed1..395614f5 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1435,6 +1435,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): kwargs.setdefault('stdin', subprocess.PIPE) kwargs.setdefault('stdout', subprocess.PIPE) kwargs.setdefault('stderr', subprocess.PIPE) + if kwargs['stdin'] == subprocess.PIPE and input is None: + # workaround for https://bugs.python.org/issue39744 + input = b'' p = yield from self.run_service(*args, **kwargs) # this one is actually a tuple, but there is no need to unpack it @@ -1471,6 +1474,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): kwargs.setdefault('stdin', subprocess.PIPE) kwargs.setdefault('stdout', subprocess.PIPE) kwargs.setdefault('stderr', subprocess.PIPE) + if kwargs['stdin'] == subprocess.PIPE and input is None: + # workaround for https://bugs.python.org/issue39744 + input = b'' p = yield from self.run(*args, **kwargs) stdouterr = yield from p.communicate(input=input)