[App] Hot fix: Resolve detection of python debugger (#16068)
Co-authored-by: thomas <thomas@thomass-MacBook-Pro.local> Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
This commit is contained in:
parent
c4b27fb69c
commit
eae56ee47b
|
@ -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
|
||||
|
||||
|
|
|
@ -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 run with a debugger attached."""
|
||||
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()
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue