Some of the information here may be outdated, please check the book instead
[edit]

Occasionally web2py has been criticized for using exec/execfile instead of import/reload for executing models and controllers. We argue that the web2py method is better for two reasons:

  • It allows to execute/import in a separate context, so there are no conflicts with class definitions and cleaner unloading of modules from memory.
  • It is faster. Benchmark below.

The test code:

import time

open('a.py','w').write('a=True')

import a
t0=time.time()
for i in range(10000): reload(a)
print time.time()-t0

t0=time.time()
for i in range(10000): execfile('a.py',{},{})
print time.time()-t0

Output:

3.61529898643
0.616114854813

Platform:

Intel Macbook (2GHz CPU + 2GB Ram)
Python 2.5.1
© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.