[Python-Dev] Reordering opcodes (PEP 203 Augmented Assignment)
Mon, 31 Jul 2000 16:47:17 +1000
> I'm still a little puzzled on this one. The only way you can view
> a running Python program in the debugger is to have started it
> within the debugger, right?
> I don't think it's possible to attach
> a debugger to an already running program.
IDLE and Pythonwin are able to debug arbitary programs once they have
started - and they are both written in Python. In addition, most debuggers
have a technique for breaking into the debugger from code - ie, a hard
break-point. pdb.set_trace() is how pdb does it. Pythonwin has one. IDLE
either does, or will grow one.
I can see a number of other problems:
* You do not want to debug the IDE itself, just a tiny bit of code running
under the IDE. Making the IDE take the full hit simply because it wants to
run a debugger occasionally isnt fair. Also, people tend to start these
IDEs once, and keep them running during a number of discrete tasks. Only a
few of these tasks may involve firing up the debugger. Asking them to
restart the IDE simply to enable the debugger would be a pain for the user.
Worse, these IDEs are often started from a GUI, rather than from the
command line. This would mean we need 2 (in Windows parlance) shortcuts -
"IDLE" and "IDLE with debugging". The end result is that all IDEs will run
with debugging enabled.
* Python often is embedded, for example, in a Web Server, or used for CGI.
It should be possible to debug these programs directly. It shouldnt be
necessary to (eg) change the CGI settings so Python is invoked with a
special flag whenever you want to use a debugger. It can be hard enought
to setup CGI as it is, let alone trying to make it's behaviour depend on if
a script needs to be debugged or not.
* We should not force Python embedders to handle this themselves. For
example, asking someone who embeds Python to support a command-line switch
to enable debugging Python is a PITA. It may not even be possible. With
Active Scripting, for example, the host may not know it is even using
Python at all!
It all seems to push the problem down to those who can least afford to
manage it, and least equipped to understand how it needs to be tweaked for
their particular situation.
However, I could agree that the debugger itself trigger debuggable
behaviour. I just dont believe this should be a startup-only switch.
sys.set_debugging(1) would work for me. OTOH, a debugger always announces
itself by calling sys.settrace(), so this is really all that is necessary
(and debugging can be disabled whenever sys.settrace(None) is called, and
no existing frames have their tracer set.)