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
This commit is contained in:
parent
3ce4e5eaa5
commit
9ec86f3c41
@ -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):
|
||||
|
@ -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')
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user