I'm new to Plone and still learning Python, so please forgive me if I ask any basic question.
I'm trying to debug code using VS Code, and everything works fine until the server starts in a new process via a subprocess.call() command. I can set breakpoints in bin/initialize, but not in Zope-4.8.10-py2.7.egg/Zope2/Startup/serve.py.
The last point where I can set a breakpoint is at line 860 of plone.recipe.zope2instance-6.12.1-py2.7.egg/plone/recipe/zope2instance/ctl.py.
I'm working with Python 2.7, so I have to use the "Debugpy Old" extension since the "Python Debugger" no longer supports Python 2. Additionally, I'm using Dev Containers, so everything runs inside a Docker container.
I want to contribute to Senaite, a laboratory information system built on top of Plone. Unfortunately, the team behind this project is struggling to keep up with version updates and provide support for everyone using the software in production environments. Moving to Python 3 is an ongoing challenge, which is why the project still uses Plone 5.
Do you think moving to Python 3 would solve my issue with VS Code debugging?
If anyone is currently working with VS Code and is able to debug Plone, regardless of the version, I would really appreciate it if you could share how you manage it.
Emiliolario via Plone Community wrote at 2024-8-15 06:11 +0000:
...
... moving to Python 3 would solve my issue with VS Code debugging?
No. Regarding debugging, there is no major difference between
Python 2 and Python 3.
For Python debugging I use both Products.PDBDebugMode
and the Python debugger (pdb).
Products.PDBDebugMode enters the Python debugger when
Plone's request processing raises an (unhandled) exception
or logs an event at level at or above ERROR provided
that Plone runs in debug mode.
With the Python debugger, you can use code breakpoints.
A code breakpoint has the from import pdb; pdb.set_trace(). set_trace() enters the Python debugger.
The Python debugger allows you to inspect the state, single step,
move up and down the call chain.
It communicates via sys.stdin and sys.stdout.
To use the debugger, you must be able to send commands to sys.stdin
and read data sent to sys.stdout.
Your question mentions specifically VS code.
There ase special tools to debug VS code -- independent of Python.
But your example refers to Python code (specifically `serve?).
Thus, you might in fact be interested in Python debugging.