Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gauge 1.5.6][Python][Debugging] PDB automatically raise BdbQuit #2424

Open
G1-Diep-Duong opened this issue Nov 1, 2023 · 12 comments
Open
Labels
bug python Pull requests that update Python code

Comments

@G1-Diep-Duong
Copy link

Describe the bug
When using pdb.set_trace(), Python-PDB automatically raise BdbQuit when meet the breakpoint.
It occurs with gauge 1.5.6, and does not occur with 1.5.5

  • OS: MacOS 14.0 Sonoma
  • Runner info (Python 3.9.18)
  • IDE info (VS Code)
@G1-Diep-Duong G1-Diep-Duong changed the title [Gauge 1.5.6][Python] PDB automatically raise BdbQuit [Gauge 1.5.6][Python][Debugging] PDB automatically raise BdbQuit Nov 1, 2023
@chadlwilson
Copy link
Contributor

@bockstaller do you think it's possible we might need for gauge-python to have its own special approach here (as you noted gauge-ruby has?)

@bockstaller
Copy link
Contributor

bockstaller commented Nov 1, 2023

It might, I'll take a look
@G1-Diep-Duong can you provide the gauge logs from gauge start until after the BdbQuit?
And could you provide the output of running gauge -v ?

@bockstaller
Copy link
Contributor

I am afraid you are correct @chadlwilson
At least when we want to support pdb.
Currently plugin ships with debugpy as the debugger of choice. Debugpy communicates over a port instead of stdin.

My guess without logs:
Calling pdb.settrace(), runs pdb, pdb looks for stdin, it has no stdin, and then quits.

@G1-Diep-Duong
Copy link
Author

It might, I'll take a look @G1-Diep-Duong can you provide the gauge logs from gauge start until after the BdbQuit? And could you provide the output of running gauge -v ?

Here is the info of gauge with gauge -v:

Gauge version: 1.5.6
Plugins

html-report (4.2.0)
python (0.4.1)
screenshot (0.1.0)
spectacle (0.1.4)

Here is the full log when running sample step:
01-11-2023 17:21:52.473 [Gauge] [DEBUG] Created gauge_screenshots_dir at /Users/diep.duongngoc/Documents/Sample/Selenium_Sample/.gauge/screenshots
01-11-2023 17:21:52.475 [Gauge] [DEBUG] Plugin html-report is already installed.
01-11-2023 17:21:52.476 [Gauge] [DEBUG] Plugin python is already installed.
01-11-2023 17:21:52.476 [Gauge] [DEBUG] Parsing started.
01-11-2023 17:21:52.476 [Gauge] [DEBUG] Started concepts parsing.
01-11-2023 17:21:52.488 [Gauge] [DEBUG] 0 concepts parsing completed.
01-11-2023 17:21:52.488 [Gauge] [DEBUG] Started specifications parsing.
01-11-2023 17:21:52.489 [Gauge] [DEBUG] 1 specifications parsing completed.
01-11-2023 17:21:52.489 [Gauge] [DEBUG] Applying tags filter: sample
01-11-2023 17:21:52.489 [Gauge] [DEBUG] The following specifications satisfy filter criteria:
01-11-2023 17:21:52.489 [Gauge] [DEBUG] specs/example.spec
01-11-2023 17:21:52.489 [Gauge] [DEBUG] Parsing completed.
01-11-2023 17:21:52.612 [python] [ERROR] /Users/diep.duongngoc/.gauge/plugins/python/0.4.1/check_and_install_getgauge.py:5: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
01-11-2023 17:21:52.612 [python] [ERROR] import pkg_resources
01-11-2023 17:21:52.981 [python] [INFO] Python: 3.9.18
01-11-2023 17:21:52.981 [python] [DEBUG] Loading step implementations from /Users/diep.duongngoc/Documents/Sample/Selenium_Sample/step_impl dirs.
01-11-2023 17:21:52.990 [python] [DEBUG] Starting grpc server..
01-11-2023 17:21:52.992 [Gauge] [DEBUG] Attempting to connect to grpc server at port: 62139
01-11-2023 17:21:52.994 [Gauge] [DEBUG] Successfully made the connection with runner with port: 62139
01-11-2023 17:21:52.994 [Gauge] [DEBUG] Validation started.
01-11-2023 17:21:52.994 [Gauge] [DEBUG] Validation completed.
01-11-2023 17:21:52.994 [Gauge] [DEBUG] Run started
01-11-2023 17:21:52.996 [Gauge] [DEBUG] Starting Html Report plugin
01-11-2023 17:21:53.025 [html-report] [DEBUG] Setting MaxRecvMsgSize = 1024 MB
01-11-2023 17:21:53.025 [Gauge] [DEBUG] Attempting to connect to grpc server at port: 62142
01-11-2023 17:21:53.026 [Gauge] [DEBUG] Successfully made the connection with plugin with port: 62142
01-11-2023 17:21:53.026 [Gauge] [DEBUG] Initialising suite data store.
01-11-2023 17:21:53.039 [Gauge] [INFO] # Getting Started with Gauge
01-11-2023 17:21:53.041 [Gauge] [INFO] ## Search
01-11-2023 17:21:53.042 [Gauge] [DEBUG] * Sample step
01-11-2023 17:21:53.050 [python] [INFO] > /Users/diep.duongngoc/Documents/Sample/Selenium_Sample/step_impl/sample.py(7)sample()
01-11-2023 17:21:53.050 [python] [INFO] -> print("SAMPLE")
01-11-2023 17:21:53.050 [python] [INFO] (Pdb)
01-11-2023 17:21:53.058 [Gauge] [DEBUG] Checking updates...
01-11-2023 17:21:53.067 [Gauge] [DEBUG] Downloading https://downloads.gauge.org/plugin/html-report?l=python&p=html-report,python,screenshot,spectacle&o=darwin&a=arm64
01-11-2023 17:21:53.242 [Gauge] [DEBUG] Downloading https://downloads.gauge.org/plugin/python?l=python&p=html-report,python,screenshot,spectacle&o=darwin&a=arm64
01-11-2023 17:21:53.281 [Gauge] [DEBUG] Downloading https://downloads.gauge.org/plugin/screenshot?l=python&p=html-report,python,screenshot,spectacle&o=darwin&a=arm64
01-11-2023 17:21:53.323 [Gauge] [DEBUG] Downloading https://downloads.gauge.org/plugin/spectacle?l=python&p=html-report,python,screenshot,spectacle&o=darwin&a=arm64
01-11-2023 17:21:53.458 [Gauge] [ERROR]
Failed Step: Sample step
01-11-2023 17:21:53.458 [Gauge] [ERROR] Error Message: Exception occurred
01-11-2023 17:21:53.458 [Gauge] [ERROR] Specification: specs/example.spec:8
01-11-2023 17:21:53.458 [Gauge] [ERROR] Stacktrace:
Traceback (most recent call last):
File "/Users/diep.duongngoc/Library/Python/3.9/lib/python/site-packages/getgauge/executor.py", line 33, in execute_method
step.impl(*params)
File "/Users/diep.duongngoc/Documents/Sample/Selenium_Sample/step_impl/sample.py", line 7, in sample
print("SAMPLE")
File "/Users/diep.duongngoc/Documents/Sample/Selenium_Sample/step_impl/sample.py", line 7, in sample
print("SAMPLE")
File "/opt/homebrew/Cellar/python@3.9/3.9.18/Frameworks/Python.framework/Versions/3.9/lib/python3.9/bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "/opt/homebrew/Cellar/python@3.9/3.9.18/Frameworks/Python.framework/Versions/3.9/lib/python3.9/bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
01-11-2023 17:21:53.460 [html-report] [DEBUG] Transformed SuiteResult to report structure
01-11-2023 17:21:53.475 [html-report] [INFO] Successfully generated html-report to => /Users/diep.duongngoc/Documents/Sample/Selenium_Sample/reports/html-report/index.html
01-11-2023 17:21:53.475 [html-report] [DEBUG] Done generating HTML report using theme from /Users/diep.duongngoc/.gauge/plugins/html-report/4.2.0/themes/default
01-11-2023 17:21:53.475 [Gauge] [DEBUG] Sending kill message to Html Report plugin.
01-11-2023 17:21:53.475 [python] [DEBUG] KillProcessrequest received
01-11-2023 17:21:53.476 [Gauge] [INFO] Specifications: 1 executed 0 passed 1 failed 0 skipped
01-11-2023 17:21:53.476 [Gauge] [INFO] Scenarios: 1 executed 0 passed 1 failed 0 skipped
01-11-2023 17:21:53.476 [Gauge] [INFO]
Total time taken: 465ms

@bockstaller
Copy link
Contributor

Ok, this looks like my suspicion is true.
Can you test if the vscode breakpoints work?

@chadlwilson chadlwilson added bug python Pull requests that update Python code labels Nov 1, 2023
@G1-Diep-Duong
Copy link
Author

G1-Diep-Duong commented Nov 2, 2023

Can you test if the vscode breakpoints work?

I tried with "Debug Scenario" function, and noticed that this issue did not occur with vscode breakpoints

@bockstaller
Copy link
Contributor

Does using "Debug Scenario" or using gauge version 1.5.5 solve your immediate problem?

@chadlwilson if this is the case, I would take a look at switching the lsp communication channel away from stdio and revert the stdin change in common instead of introducing more special cases.

@G1-Diep-Duong
Copy link
Author

G1-Diep-Duong commented Nov 2, 2023

@bockstaller
Yes, of course it solved this issue, but I still prefer to use pdb.set_trace() more than using built_in function "Debug Scenario" because I can use some customized args for executing, e.g gauge run -v -t "sample|udid:emulator-5554", and I don't know how to add these args when running with built_in function "Debug Scenario" =))
Thankz.

@chadlwilson
Copy link
Contributor

@chadlwilson if this is the case, I would take a look at switching the lsp communication channel away from stdio and revert the stdin change in common instead of introducing more special cases.

I'm not sure I know enough about LSP to know the right way forward here. Maybe @sriv or @zabil or @haroon-sheikh have an opinion?

@sriv
Copy link
Member

sriv commented Nov 2, 2023

I am not very well versed in the python stack, but a cursory look tells me that pdb is similar to ruby pry i.e. a CLI debugger that requires stdin to be passed through. I am not sure if we could make gauge-python do what gauge-ruby does, but that is certainly an option.

Short of that, we may need to switch using pipe or socket as jsonrpc transport.

@G1-Diep-Duong
Copy link
Author

Manual debugging (outside IDE) confirms the issue persists in v1.6.1. As this is a critical bug, I recommend prioritizing its fix.
image

@chadlwilson
Copy link
Contributor

I'm afraid the project doesn't have the necessary contributors and knowledge to prioritise this without further outside help.

I guess we implicitly decided fixing the wider vscode issues with the language server (especially typescript usage) were higher priority than continued confidence in debugging via PDB or other plugins relying on stdio - which is unfortunate, but probably unavoidable given the current maintenance situation. :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug python Pull requests that update Python code
Development

No branches or pull requests

4 participants