Fix #72: "Wait on exit" blocks indefinitely when there's no terminal

Block use of "waitOnNormalExit" and "waitOnAbnormalExit" with "console":"internalConsole".

Do not wait on exit if stdin is not interactive (e.g. when running under pythonw.exe).
This commit is contained in:
Pavel Minaev 2020-03-12 18:14:24 -07:00 committed by Pavel Minaev
parent a0ca896b26
commit d12f1d27ef
2 changed files with 23 additions and 8 deletions

View file

@ -141,15 +141,15 @@ def wait_for_exit():
def _wait_for_user_input():
if sys.stdout and sys.stdin:
if sys.stdout and sys.stdin and sys.stdin.isatty():
from debugpy.common import log
can_getch = sys.stdin.isatty()
if can_getch:
try:
import msvcrt
except ImportError:
can_getch = False
try:
import msvcrt
except ImportError:
can_getch = False
else:
can_getch = True
if can_getch:
log.debug("msvcrt available - waiting for user input via getch()")

View file

@ -126,12 +126,19 @@ def launch_request(request):
if request("gevent", False):
env["GEVENT_SUPPORT"] = "True"
console = request(
"console",
json.enum(
"internalConsole", "integratedTerminal", "externalTerminal", optional=True
),
)
redirect_output = property_or_debug_option("redirectOutput", "RedirectOutput")
if redirect_output is None:
# If neither the property nor the option were specified explicitly, choose
# the default depending on console type - "internalConsole" needs it to
# provide any output at all, but it's unnecessary for the terminals.
redirect_output = request("console", unicode) == "internalConsole"
redirect_output = console == "internalConsole"
if redirect_output:
# sys.stdout buffering must be disabled - otherwise we won't see the output
# at all until the buffer fills up.
@ -140,8 +147,16 @@ def launch_request(request):
env["PYTHONIOENCODING"] = "utf-8"
if property_or_debug_option("waitOnNormalExit", "WaitOnNormalExit"):
if console == "internalConsole":
raise request.isnt_valid(
'"waitOnNormalExit" is not supported for "console":"internalConsole"'
)
debuggee.wait_on_exit_predicates.append(lambda code: code == 0)
if property_or_debug_option("waitOnAbnormalExit", "WaitOnAbnormalExit"):
if console == "internalConsole":
raise request.isnt_valid(
'"waitOnAbnormalExit" is not supported for "console":"internalConsole"'
)
debuggee.wait_on_exit_predicates.append(lambda code: code != 0)
if sys.version_info < (3,):