forked from VimPlug/jedi
Remove stdout/stderr from subprocesses (redirected to /dev/null)
This means that the subprocess should now not crash anymore because of people writing to stdout in c modules and stderr should be empty. Fixes #793.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user