Skip to content

Commit

Permalink
Fix microsoft#304: Breakpoints not working with QThread/PySide2
Browse files Browse the repository at this point in the history
Expose pydevd.enable_qt_support() in debugpy.server via debugpy.configure(qt=...) and --configure-qt ...

Expose the same in debugpy.adapter via "qt" debug configuration property.

Default to "auto" for all of the above, and also provide "none" to disable Qt monkey-patching entirely.
  • Loading branch information
int19h committed Jun 25, 2020
1 parent b8e66cb commit e8bd6c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/debugpy/launcher/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,18 @@ def property_or_debug_option(prop_name, flag_name):
"--connect",
launcher.adapter_host + ":" + str(port),
]

if not request("subProcess", True):
cmdline += ["--configure-subProcess", "False"]

qt_mode = request(
"qt",
json.enum(
"auto", "none", "pyside", "pyside2", "pyqt4", "pyqt5", optional=True
),
)
cmdline += ["--configure-qt", qt_mode]

adapter_access_token = request("adapterAccessToken", unicode, optional=True)
if adapter_access_token != ():
cmdline += ["--adapter-access-token", compat.filename(adapter_access_token)]
Expand Down
18 changes: 17 additions & 1 deletion src/debugpy/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
_tls = threading.local()

# TODO: "gevent", if possible.
_config = {"subProcess": True}
_config = {
"qt": "auto",
"subProcess": True,
}

_config_valid_values = {
# If property is not listed here, any value is considered valid, so long as
# its type matches that of the default value in _config.
"qt": ["auto", "none", "pyside", "pyside2", "pyqt4", "pyqt5"],
}

# This must be a global to prevent it from being garbage collected and triggering
# https://bugs.python.org/issue37380.
Expand Down Expand Up @@ -85,6 +94,9 @@ def configure(properties, **kwargs):
expected_type = type(_config[k])
if type(v) is not expected_type:
raise ValueError(fmt("{0!r} must be a {1}", k, expected_type.__name__))
valid_values = _config_valid_values.get(k)
if (valid_values is not None) and (v not in valid_values):
raise ValueError(fmt("{0!r} must be one of: {1!r}", k, valid_values))
_config[k] = v


Expand All @@ -109,6 +121,10 @@ def debug(address, **kwargs):
log.debug("{0}({1!r}, **{2!r})", func.__name__, address, kwargs)
log.info("Initial debug configuration: {0!j}", _config)

qt_mode = _config.get("qt", "auto")
if qt_mode != "none":
pydevd.enable_qt_support(qt_mode)

settrace_kwargs = {
"suspend": False,
"patch_multiprocessing": _config.get("subProcess", True),
Expand Down
2 changes: 1 addition & 1 deletion src/debugpy/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Options(object):


options = Options()
options.config = {"subProcess": True}
options.config = {"qt": "auto", "subProcess": True}


def in_range(parser, start, stop):
Expand Down

0 comments on commit e8bd6c1

Please sign in to comment.