www.8devices.com
View unanswered posts | View active topics It is currently 20 Oct 2017, 18:04



Reply to topic  [ 8 posts ] 
 Will Python ware out Carambola 2 internal flash? 
Author Message

Joined: 18 Nov 2013, 18:44
Posts: 51
Hi,
am I wrong to fear python wearing out internal flash? Is python script being compiled each time it is run or only first time? Is compiled binary being written to flash or is it only kept in ram?

Thanks.


23 Jun 2015, 09:33
Profile
8devices
8devices

Joined: 11 Jun 2014, 14:45
Posts: 135
Python scripts are compiled only when needed (i.e. the source file has changed) and in general it should not be an issue. Even if the code changes from time to time it won't be an issue. It should only be of concern if you have a frequent (beyond human typing limits) code generation and execution. In that case you could use the RAM disk (work in /tmp directory) or python's -B flag (less preferable).


23 Jun 2015, 12:35
Profile

Joined: 18 Nov 2013, 18:44
Posts: 51
Thank for explaining.


25 Jun 2015, 07:57
Profile

Joined: 18 Nov 2013, 18:44
Posts: 51
Strange, I actually don't see any pyc files being created in /bin/ folder where my python files are located.

Using find / -name *.pyc shows only few *.pyc files in /usr/lib/python2.7/

Strange... so what is happening? Are pyc files not being created at all when I run my python scritps on Carambola 2? Or are created and deleted?


26 Jun 2015, 07:48
Profile
8devices
8devices

Joined: 11 Jun 2014, 14:45
Posts: 135
.pyc file are not generated for the script that you run, but rather for the libraries (other .py files) it imports. If you have myscript.py which imports mylib(.py), then after running
Code:
python myscript.py; ls
you should see mylib.py, mylib.pyc and myscript.py.


26 Jun 2015, 13:38
Profile

Joined: 18 Nov 2013, 18:44
Posts: 51
Thanks for clarifying that!


26 Jun 2015, 15:21
Profile

Joined: 15 Nov 2013, 11:38
Posts: 10
Hello valent,

You should also have a look at this change in the OpenWRT package : https://github.com/openwrt/packages/pull/541
Depending of the version of OpenWRT you're using, byte code may be disabled by default by this patch : https://github.com/openwrt/packages/blo ... odes.patch.
In that case, pyc files will not be created, and python is quite slow. To enable byte code to be generated, you have to add :
Code:
export PYTHONDONTWRITEBYTECODE=0
in /etc/profile


19 Oct 2015, 11:26
Profile

Joined: 18 Nov 2013, 18:44
Posts: 51
After needing python to work faster for my day job, in startup that I work for we use Python on OpenWrt... and finally found the solution!

To compile all python modules into pyc issue this command:
Code:
python -m compileall


Make sure you have at least 7MB of internal storage space!

Now my python scripts start under 1.5 seconds and previously it would take them 6-8 seconds!

If you have additional python modules installed you need to compile them also, so for me I needed to additionally run these commands:
Code:
python -m compileall /usr/lib/python2.7/site-packages/serial/*.py
python -m compileall /usr/lib/python2.7/site-packages/serial/tools/*.py
python -m compileall /usr/lib/python2.7/site-packages/serial/urlhandler/*.py

YMMV, enjoy!


08 Mar 2017, 21:05
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Protected by Anti-Spam ACP Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.