Jump to content

Python being Slow and CPU Intensive? Fix is here!


Zylla

Recommended Posts

On our devices it is possible to run Python code, but even a simple "Hello World" Python script can take up 6-8 seconds to run, at worst!
Investigations seems to show that all Python modules are kept in .py source code, and is compiled in memory on each run. (To save space i guess)
Due to having alot of modules and that we're using small embedded devices, this causes delays in even the simplest of Python-related code!

Example:
Alot of the python scripts on my Mana Toolkit is slow, and causes the CPU-usage to sky-rocket.

So what can we do do 'fix' this?
Open a SSH terminal to your Pineapple and issue this command:

python -m compileall

This causes python to pre-compile all your python modules to .pyc-files. Which is located at: /usr/lib/python2.77

This fix is relative straight-forward on the TETRA.
On the NANO we're better of moving that directory to the SD-card and issue a sym-link from that directory to: /usr/lib/python2.7 before we run the commmand. (Saves internal storage)
For example like this:

mv /usr/lib/python2.7 /sd/usr/lib/python2.7
ln -s /sd/usr/lib/python2.7 /usr/lib/python2.7
python -m compileall

 

You can also pre-compile the python files within the directory you're inside by using the same command, but adding a dot at the end, like this:

python -m compileall .

 

This was a huge improvement for me. Hope it can be of usage for you guys :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...