diff --git a/jedi/evaluate/compiled/subprocess/__init__.py b/jedi/evaluate/compiled/subprocess/__init__.py index bc9abaf1..2a20f174 100644 --- a/jedi/evaluate/compiled/subprocess/__init__.py +++ b/jedi/evaluate/compiled/subprocess/__init__.py @@ -142,7 +142,6 @@ class _CompiledSubprocess(object): args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - # stderr=subprocess.PIPE ) def run(self, evaluator, function, args=(), kwargs={}): @@ -266,6 +265,11 @@ class Listener(object): def listen(self): stdout = sys.stdout + # Mute stdout/stderr. Nobody should actually be able to write to those, + # because stdout is used for IPC and stderr will just be annoying if it + # leaks (on module imports). + sys.stdout = open(os.devnull, 'w') + sys.stderr = open(os.devnull, 'w') stdin = sys.stdin if sys.version_info[0] > 2: stdout = stdout.buffer diff --git a/jedi/evaluate/compiled/subprocess/functions.py b/jedi/evaluate/compiled/subprocess/functions.py index a78719fe..593ff91e 100644 --- a/jedi/evaluate/compiled/subprocess/functions.py +++ b/jedi/evaluate/compiled/subprocess/functions.py @@ -2,7 +2,7 @@ import sys import os from jedi._compatibility import find_module, cast_path, force_unicode, \ - iter_modules, all_suffixes + iter_modules, all_suffixes, print_to_stderr from jedi.evaluate.compiled import access from jedi import parser_utils @@ -85,6 +85,18 @@ def _test_raise_error(evaluator, exception_type): raise exception_type +def _test_print(evaluator, stderr=None, stdout=None): + """ + Force some prints in the subprocesses. This exists for unit tests. + """ + if stderr is not None: + print_to_stderr(stderr) + sys.stderr.flush() + if stdout is not None: + print(stdout) + sys.stdout.flush() + + def _get_init_path(directory_path): """ The __init__ file can be searched in a directory. If found return it, else diff --git a/test/test_api/test_environment.py b/test/test_api/test_environment.py index fc02c990..6bc59a4c 100644 --- a/test/test_api/test_environment.py +++ b/test/test_api/test_environment.py @@ -67,6 +67,11 @@ def test_error_in_environment(evaluator, Script): assert def_.name == 'str' +def test_stdout_in_subprocess(evaluator, Script): + evaluator.compiled_subprocess._test_print(stdout='.') + Script('1').goto_definitions() + + def test_killed_subprocess(evaluator, Script): # Just kill the subprocess. evaluator.compiled_subprocess._compiled_subprocess._process.kill()