dhylands / upy-shell

MicroPython shell
MIT License
38 stars 10 forks source link

pyboard.py Fix for rshell issue #7 #12

Open peterhinch opened 8 years ago

peterhinch commented 8 years ago

For some reason my recent HP zbook takes some 15 seconds before the Pyboard is recognized. If invoked during this time rshell threw an exception. This patch fixes this: it behaves sensibly whether the Pyboard is plugged in before or after invoking rshell.

I'm puzzled why I have to do sys.stdout.flush()

dhylands commented 8 years ago

The need for a flush is because stdout is line buffered by default, so characters just accumulate in memory until a newline is seen and then the call write is made. This is C runtime library behaviour and not specific to python. Adding the flush call causes the accumulated data to be written before the newline is seen.

I'll take a look at this. Thanks

dhylands commented 8 years ago

If for some reason, they don't take the patch, I'm pretty sure I can do something similar in rshell when it constructs the Pyboard object. (the loop just moves into rshell.py instead of being in pyboard.py

peterhinch commented 8 years ago

I've submitted a PR. I used your suggestion re else, but had to make a few other changes when I tested pyboard.py on its own because it uses Python 2.x by default. Hopefully it will be accepted because in my view it improves pyboard too.

As for flush I should have remembered that - I was assuming a complicated reason when a simple one sufficed ;-)