rzel / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

ipm executes after one typed line inside a while loop #206

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the following on desktop ipm:

  ipm> a = 12
  ipm> while True:
  ....   a = a + 1

What is the expected output? What do you see instead?
Expect to be able to type another line.  Instead, VM goes into the loop, ipm 
stops responding.

Original issue reported on code.google.com by dwhall...@gmail.com on 26 Jun 2011 at 3:31

GoogleCodeExporter commented 9 years ago
On my setup I'm calling the _runsource() you made for me from wxPython's shell 
and I can do this fine:

>>> a = 12
>>> while True:
...     a = a + 1
...     if a > 15:
...         break
...     
>>> a
16
>>> 

It appears that it was me that introduced this bug.  You used my code for 
onecmd() and I did not strip the trailing newline before calling _runsource().  
The problem is that you can't always strip the newline or you will never finish 
a loop.  I think the fix is to do an rstrip() on each new line as it is 
gathered.  Then a newline and the new line.  So instead of this:

                line += self.stdin.readline()

do this:
                new_line = self.stdin.readline().rstrip()
                line += '\n' + new_line

Original comment by j...@missioncognition.net on 26 Jun 2011 at 4:27

GoogleCodeExporter commented 9 years ago
Or you could change the line to this:
        line += '\n' + self.stdin.readline().rstrip()

It seems to work in all the test cases I tried.

Original comment by j...@missioncognition.net on 26 Jun 2011 at 8:21

GoogleCodeExporter commented 9 years ago
Thank you for the prompt fix.  I've applied it and tested it on desktop and 
mbed and it works nicely.

Original comment by dwhall...@gmail.com on 29 Jun 2011 at 2:33

GoogleCodeExporter commented 9 years ago
This issue was closed by revision df87e0f232f7.

Original comment by dwhall...@gmail.com on 29 Jun 2011 at 2:36