Re: Importing Cheetah.Template.Template unusually slow?
Graham Dennis <[email protected]> Thu, 28 Jan 2010 09:49:29 +1100
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
On 28 Jan 2010, at 8:19 AM, Matthew Beauregard wrote:
>
> So I guess I'd have to blame some interaction between Cheetah and Apple's framework python. I'm not sure what to do next.
I remember having this problem myself and I traced it down to Servlet.py where it tries to do:
from WebKit.Servlet import Servlet as BaseServlet.
What's happening here is that on Mac OS X Leopard and later the 'WebKit' import resolves to the system framework WebKit which is available via the PyObjC bridge. However, once the import of 'WebKit' has succeeded, 'WebKit.Servlet' fails, and you're wasting much of your time on a line that does nothing.
I created a hack to get around this which installs an empty module called 'WebKit' (only on Mac OS X), so that when Cheetah tries to import WebKit it gets this module instead and fails much faster.
def leopardWebKitHack():
"""
Hack for Mac OS X Leopard and above so that it doesn't import
the web rendering framework WebKit when Cheetah tries to import
the Python web application framework WebKit.
"""
if sys.platform == 'darwin' and not 'WebKit' in sys.modules:
module = type(sys)
sys.modules['WebKit'] = module('WebKit')
Just make sure you call that before importing Cheetah.Template.
time python -c 'from Cheetah.Template import Template'
real 0m0.682s
user 0m0.550s
sys 0m0.121s
time python -c 'import sys; sys.modules["WebKit"] = type(sys)("WebKit");from Cheetah.Template import Template'
real 0m0.130s
user 0m0.083s
sys 0m0.044s
Cheers,
Graham
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss