debugpy/ptvsd/debugger.py
Eric Snow 617727ef7c
Clean up session handling in the daemon. (gh-463)
This is part of the effort to fix gh-459. While it doesn't fix it, it does clean up the Daemon code a little and resolves a potential issue with session lifecycle handling. The solution for gh-459 will build on this.
2018-06-07 11:52:35 -06:00

37 lines
945 B
Python

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
import sys
from ptvsd._local import run_module, run_file
# TODO: not needed?
DONT_DEBUG = []
LOCALHOST = 'localhost'
RUNNERS = {
'module': run_module, # python -m spam
'script': run_file, # python spam.py
'code': run_file, # python -c 'print("spam")'
None: run_file, # catchall
}
def debug(filename, port_num, debug_id, debug_options, run_as,
_runners=RUNNERS, _extra=None, *args, **kwargs):
# TODO: docstring
if _extra is None:
_extra = sys.argv[1:]
address = (LOCALHOST, port_num)
try:
run = _runners[run_as]
except KeyError:
# TODO: fail?
run = _runners[None]
if _extra:
args = _extra + list(args)
kwargs.setdefault('singlesession', True)
run(address, filename, *args, **kwargs)