Bob.S.P
Bob.S.P

Reputation: 85

Python-PDB automatically raise BdbQuit

I have been using pdb.set_trace() to set some breakpoints in my codes, and always it was smooth.

I have a shell script that run a python script inside a loop:

cat $file1 | (
#read something from file1
while ... 
do
   if ... then
      cat $file2 | (
      # read something from file2
      while ...
          do 
               python test.py
               # read something from file2
          done)
   fi
   #read something from file1
done)

Assume that test.py is just a simple hello world. I put pdb.set_trace() in my python script. When I run the code outside the loop, simply by python test.py, everything is ok. However, when I execute the .sh script, the moment that it gets to the pdb.set_trace(), it raises a BdbQuit and quite my python script.

I could not realize what the problem is. I really appreciate if anyone can help me to figure this out.

Thank you.

Upvotes: 1

Views: 1981

Answers (1)

larsks
larsks

Reputation: 312370

You are redirecting stdin inside the while loop:

cat $file1 | while ...

The interactive pdb prompt reads from stdin as well, but since it's been redirected, it's just going to take input from that file.

The easiest solution in this case is just to use something like remote-pdb, which opens up a network connection to which you can connect using e.g. telnet or nc.

Upvotes: 1

Related Questions