Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lightning_app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Fixed `AutoScaler` raising an exception when non-default cloud compute is specified ([#15991](https://github.com/Lightning-AI/lightning/pull/15991))

- Fixed the debugger detection mechanism for lightning App in VSCode ([#16068](https://github.com/Lightning-AI/lightning/pull/16068))


## [1.8.4] - 2022-12-08

Expand Down
23 changes: 20 additions & 3 deletions src/lightning_app/utilities/app_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,29 @@ def _lightning_dispatched() -> bool:
return bool(int(os.getenv("LIGHTNING_DISPATCHED", 0)))


def _using_debugger() -> bool:
"""This method is used to detect whether the app is runned run a debugger attached to it."""
if "LIGHTNING_DETECTED_DEBUGGER" in os.environ:
return True

# Collect the information about the process.
parent_process = os.popen(f"ps -ax | grep -i {os.getpid()} | grep -v grep").read()

# Detect whether VSCode or PyCharm debugger are used
use_debugger = "debugpy" in parent_process or "pydev" in parent_process

# Store the result to avoid multiple popen calls.
if use_debugger:
os.environ["LIGHTNING_DETECTED_DEBUGGER"] = "1"
return use_debugger


def _should_dispatch_app() -> bool:
return (
__debug__
and "_pytest.doctest" not in sys.modules
and not _lightning_dispatched()
not _lightning_dispatched()
and "LIGHTNING_APP_STATE_URL" not in os.environ
# Keep last to avoid running it if already dispatched
and _using_debugger()
)


Expand Down