[wingide-users] Debugging source generated by calling "python
Wing IDE Support
support at wingware.com
Tue Aug 17 22:56:36 EDT 2004
On Tue, 17 Aug 2004, Diener, Edward wrote:
> In my Python code in myfile.py I need to start Python again by calling
> "python myfile.py" in another process. I need to debug myfile.py a
> second time once this happens. Furthermore I need to call python in this
> way from another command processor, via "system("python somefile.py |
> python myfile.py otherparms")", and be able to debug myfile.py as it
> runs again under the new command processor. I have read the topic of
> 6.14.0 on importing the debugger and have tried this out adding "import
> wingdbstub" to myfile.py. When I originally start myfile.py from a
> command prompt, the debugger does stop the first time in myfile.py and I
> can debug the file up until I call "system("python somefile.py | python
> myfile.py otherparms")" from within myfile.py. But even though myfile.py
> is being re-executed again from the new command processor, the debugger
> does not re-enter it at the point where my "import wingdbstub" exists.
> Is there any way to have the debugger re-enter my code a second time ?
> Barring that is there any way of having the debugger enter the second
> time even if it means that I it does not enter the code the first time,
> since the code up until the "system("python somefile.py | python
> myfile.py otherparms")" works fine ?
Wing doesn't support multiple simultaneous debug connections right now
which is why your second invocation is being run w/o debug. Its attempt
to connect to the IDE fails because the IDE is busy already, and the
second process continues with normal execution.
This scenario is somewhat of a pain to debug. It is possible to run two
copies of Wing, configure one to use a different TCP/IP port for the debug
connection, and then set up two copies of wingdbstub that use the
different ports. However, if you're running the same file twice you'ld
have to provide logic to import one copy of wingdbstub the first time and
another the second. Not the most elegant solution, obviously, but if you
decide to do this you'll probably want to use --prefs-file command line
option when starting the second instance of Wing to avoid fighting between
the two copies when you configure different debug port numbers.
Another approach would be to use popen() from myfile.py instead of
piping in your os.system() call. Then the first invocation of myfile.py
can also process the output of somefile.py, and you don't have the
problem of having a second invocation running concurrently:
pipe = os.popen("python somefile.py")
# Pass pipe and "otherparms" to second myfile.py invocation
The pipe should be just about as fast and it doesn't sound like this
alters your degree of concurrency, tho it does assume there isn't global
state in myfile.py that will get trounced, and you would need to move the
top level of myfile.py to a function so you can invoke it a second time
Heck, dare I suggest it, you can also reset sys.stdin and sys.argv
temporarily around the second call (be sure to save and restore the old
values tho!). Something like:
save_in = sys.stdin
save_args = sys.argv
sys.stdin = os.popen("python somefile.py")
sys.argv = otherparms
# Call function for second myfile.py invocation
sys.stdin = save_in
sys.argv = save_args
Of course you could also just rewrite things so myfile.py just imports
somefile.py and calls functions, but the above hack requires less recoding
if this is temporary and/or you need the pipe for performance reasons.
Sorry I don't have a better answer... We do plan to add concurrent debug
connections in the future, just not before 2.0 final.
Hope that helps.
Wing IDE for Python
Advancing Software Development
More information about the wingide-users