Menu

More Python Shell fun

Jake L
2019-09-12
2019-09-12
  • Jake L

    Jake L - 2019-09-12

    Hello,
    How can I get the python scripting shell to stop using between 80% to 99% of my laptop's CPU resources? (lubuntu 19.04) I do not have this CPU overloading problem within other serial emulators like minicom while connected to the same FF hardware. I really want to keep using the history log in the ff-shell though or I'd just use Minicom. I have had the same issue with the PIC18F26K22, F46K22, and an ATmega328. I have all 3 working with the default settings in the build files or at least the settings noted in the pdf user guide. I have tried using the Serial port XON/XOFF enabled and disabled. If enabled it helps reduce the CPU load from 95-99% to 90-95%. I have tried reading a bunch of info about python, and messed around with the ff-shell file for days, but I still have no clue where the issue is. I don't think the issue is on the microcontroller side as I haven't had any problems like this in minicom. The CPU usage never goes above 10% while connected to minicom. When I open the ff-shell.py file in Gedit I think I may have been getting formatting errors so I have downloaded a second clone of the directory, backed up the files, and tried to learn/use Pycharm, and Geany. I also made it through 2/3rds of Code Acadamy's 4 hour Python class. Read the bulk of info on POSIX serial, PySerial, and even went through a whole tutorial on writting a serial emulator in C with GCC before realizing the poor state of my general hobbyist C skills is not much better. Plus the tutorial left me hanging just after it got me sending and receiving single files. Please help me get out of this rabbit hole :-)

     
  • Mikael Nordman

    Mikael Nordman - 2019-09-12

    I have always had 100 % core usage with ffshell.py.
    It is annoying, if your on batteries and a laptop.
    I think it is caused by the python readline library implementation.
    If you find an improvement, please post it.

     
  • Mikael Nordman

    Mikael Nordman - 2019-09-12

    I had a quick look and maybe it is actally the serial.read() that is consuming CPU.
    There are some pyserial timeout params that can tried.

     
  • Mikael Nordman

    Mikael Nordman - 2019-09-12

    I have updated the ff-shell.py not to cause 100% load anymore.
    Now the idle load is more like 0.1 %
    BR Mikael

     
  • Jake L

    Jake L - 2019-09-12

    Thanks! It's so efficient I can't even get it to show up under Top :-)

    Not that it matters but I have been adding 'print ""' below line 65.
    if char == '\n': *
    waitForNL = 0
    >
    print "" *
    This just makes the "ok<#,ram>" message appear on the next line every time I press enter on the keyboard. It's not necessary but I just like it. Without that line I don't get a \n responce from pressing enter.
    Next, I compiled the FF5 code and uploaded it to several uC's and all of them have the default <control-o> setting disabled. I'll probably change that at some point but it is set to default for now. Instead of using Control-O, I added the following at line 136:</control-o>

    • if line[:5] == "#exit":
      raise e*
      This effectivly closes the port connection.

    Lastly, maybe someone like myself will read and find the following bit helpful.
    I was typing all of this on the command line just to start the ff-shell:
    python /home/jake/flashforth/shell/ff-shell.py -p /dev/ttyUSB0 -s 38400
    I looked up how to write a bash script to open this with less typing or scrolling through history. These are the commands I used:
    $ echo python /home/jake/flashforth/shell/ff-shell.py -p /dev/ttyUSB0 -s 38400 > ff5.sh
    Then...
    $ sudo chmod 755 ff5.sh
    Then...
    $ sudo mv ~/ff5.sh /usr/local/bin/ff5.sh

    Now I just need to type ff5.sh on the command line and it opens ff-shell.py and has all of my settings ready. I just find ff5.sh easier to type and remember.
    Thanks again Mikael for getting the CPU use under control.
    -Jake

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.