Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Compile everything with a one-liner

The other day, we noticed that the .py files in our main mod_python application at work did not have corresponding compiled .pyc files. mod_python runs as the unprivileged apache user, which on our server doesn’t have the required permissions to write the compiled .pyc files in to the directories in which our code lives.

A bit of digging came up with the compileall module, which provides functions for byte-compiling Python files in bulk. We invoked it using the following shell one-liner, executed at the upper most directory of our code tree:

python2.3 -c "import compileall; compileall.compile_dir('.')"

Executed as root, the result was a full set of .pyc bytecode files.

This is Compile everything with a one-liner by Simon Willison, posted on 1st July 2004.

View blog reactions

Next: PHP 5 is out!

Previous: Fancy a job?

7 comments

  1. and, was there any noticable speedup?

    sfb - 1st July 2004 20:34 - #

  2. That's an excellent trick. You've also introduced a cool module. Off to try it myself.

    -Josh

    Josh Sklar - 1st July 2004 20:42 - #

  3. sfb: it's very hard to say; our apps were pretty fast to begin with.

    Simon Willison - 1st July 2004 22:06 - #

  4. Why not giving more permissions ot mod_python in the first place ?

    Lawouach - 2nd July 2004 08:44 - #

  5. Well, its a Good Thing to not give Apache more permission then it really needs.

    Ian Monroe - 2nd July 2004 23:50 - #

  6. evil of men is creation of money...and it's enemy of all enemy!!!

    ankur mehta - 4th December 2004 04:48 - #

  7. compileall.py has an if __name__ == "__main__" in it; I've used
    python /usr/lib/python2.1/compileall.py .
    
    in package installs before (though I guess your invocation could be python-version independent if you just invoked "python" instead of python2.3...)

    Mark Eichin - 13th August 2005 23:01 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2004/07/01/compileall

A django site