[Python-Dev] Embedded Python startup is slow

Glyph Lefkowitz glyph at twistedmatrix.com
Thu Mar 24 10:19:02 CET 2011


On Mar 24, 2011, at 4:06 AM, bruce bushby wrote:

> I have previously asked this question in python-list, however I think it belongs here.

As the saying goes, this list is for development of python, not with python.  So it would be appropriate to make a suggestion as to some direction for Python's development that would improve your situation.

That said, at one point I had similar issues, and I also thought that Python should have had some kind of "embedded mode" compilation options, and I never found anything.

> I'm running python 2.7.1 on an embedded Linux board and noticed it takes 1.8 seconds to execute the most simple "Hello World" script.

You will notice that very, very early on in the process (not quite the first thing, but almost), there is a stat for python27.zip.  You want to put absolutely everything in the standard library into that archive, and to put your shared objects into /usr/lib/python2.7/ with names like 'foo.so' (not 'foomodule.so', as that's statted second).

When I was working with embedded python, that was pretty much the whole story: 2 zip files (one for the stdlib, one for everything else in my application), one directory for extension modules.  Finally, I hacked site.py to set sys.path to just those three entries, so that even failed imports would not stat too many non-existent files.

I think it would be a great idea to have a configure flag that instructed python to be pre-built this way, but I don't work with embedded pythons these days, so I'm not likely to do it :).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20110324/89559f9d/attachment.html>


More information about the Python-Dev mailing list