From 7f601a5582bad1af82f1f4bb40c5c7eff64a6218 Mon Sep 17 00:00:00 2001 From: rdugan <1779672+rdugan@users.noreply.github.com> Date: Mon, 24 Feb 2020 11:13:03 -0800 Subject: [PATCH 1/2] Switch to Popen.communicate() to avoid IO deadlocks --- pyls/plugins/flake8_lint.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyls/plugins/flake8_lint.py b/pyls/plugins/flake8_lint.py index 69f3f40a..2b55e17d 100644 --- a/pyls/plugins/flake8_lint.py +++ b/pyls/plugins/flake8_lint.py @@ -58,11 +58,10 @@ def run_flake8(args): cmd = ['python', '-m', 'flake8'] cmd.extend(args) p = Popen(cmd, stdout=PIPE, stderr=PIPE) - stderr = p.stderr.read().decode() + (stdout, stderr) = p.communicate() if stderr: - log.error("Error while running flake8 '%s'", stderr) - stdout = p.stdout - return stdout.read().decode() + log.error("Error while running flake8 '%s'", stderr.decode()) + return stdout.decode() def build_args(options, doc_path): From ace0a7327ec735085c5d0b5e841ea789a8e28a47 Mon Sep 17 00:00:00 2001 From: rdugan <1779672+rdugan@users.noreply.github.com> Date: Fri, 28 Feb 2020 21:35:57 -0800 Subject: [PATCH 2/2] Updated flake8 test to use mocked Popen.communicate() --- test/plugins/test_flake8_lint.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/plugins/test_flake8_lint.py b/test/plugins/test_flake8_lint.py index d4858f8e..b675fe93 100644 --- a/test/plugins/test_flake8_lint.py +++ b/test/plugins/test_flake8_lint.py @@ -56,6 +56,8 @@ def test_flake8_lint(config): def test_flake8_config_param(config): with patch('pyls.plugins.flake8_lint.Popen') as popen_mock: + mock_instance = popen_mock.return_value + mock_instance.communicate.return_value = [bytes(), bytes()] flake8_conf = '/tmp/some.cfg' config.update({'plugins': {'flake8': {'config': flake8_conf}}}) _name, doc = temp_document(DOC)