4

I'm currently writing an AI assignment for class, and each time I try to debug (using ipdb or pdb) pdb closes immediately. The program takes a map as input, and right now I'm just piping the text file in and grabbing the lines from stdin.

python value_iteration.py < l_track.txt

This works fine, but I think it's causing pdb.set_trace() to close, is there a way to explicitly make sure that stdin is freed or something?

Current map grabbing code segment:

def map_input():
...
control_line = sys.stdin.readline().rstrip('\n')
height, width = control_line.split(",")
height = int(height)
width = int(width)

print "Map:"
while row < height:
    for line in sys.stdin:
        create MDP from states
...
return mdp

Then:

def value_iteration(mdp, epsilon):
....
for state in mdp.states.keys():
     print mdp.actions[state]
     ipdborpdb.set_trace()
     utils_prime[state] = R(state) + gamma * max([
        sum([
           p * mdp.utilities[ns] for (p, ns) in T(state, a)
        ]) for a in mdp.actions[state]
     ])
     if abs(utils_prime[state] - mdp.utilities[state]) > delta:
        delta = abs(utils_prime[state] - mdp.utilities[state])
...
return mdp with utilities
Murph
  • 511
  • 7
  • 16
  • 1
    at least show us where is the pos of "pdb.set_trace()" – fanlix Dec 05 '12 at 03:23
  • 2
    this is pdb problem, try read: http://stackoverflow.com/questions/9178751/use-pdb-set-trace-in-a-script-that-reads-stdin-via-a-pipe – fanlix Dec 05 '12 at 03:35
  • Yeah I saw that question, asked my own since that one had no fixes or answers. – Murph Dec 05 '12 at 03:41
  • 1
    i think answers are inside that question: 1, change for other debug tool; 2, separate pdb's io to another fifo – fanlix Dec 05 '12 at 03:55
  • or the best way, i think, read your data from file directly, not by OS's pipe – fanlix Dec 05 '12 at 03:57
  • Not sure how to separate to another fifo, but I'd really like to just be able to use what I have. Shouldn't have to get wxPython/Winpdb just to debug a simple script. I'll just switch to reading from a filename then. – Murph Dec 05 '12 at 04:02

1 Answers1

0

I never figured out how to fix this, so I switched to using a filename input.

Murph
  • 511
  • 7
  • 16