Re: Importing Cheetah.Template.Template unusually slow?

Tavis Rudd <[email protected]> Wed, 27 Jan 2010 17:45:46 -0800 (PST)
Newsgroups gmane.comp.python.cheetah
Message-ID <alpine.LNX.2.00.1001271741300.19278@o2>

On Wed, 27 Jan 2010, R. Tyler Ballance wrote:

>
> On Thu, 28 Jan 2010, Graham Dennis wrote:
>
>> I tried to post this message earlier, but I think my mail server is having a hissy fit.  Apologies if anyone gets this twice.
>
> I think you're onto something here :)
>
> I'm willing to bet that the framework builds have sys.path set such that the
> Apple WebKit module can be imported properly whereas the macports build would
> not have the proper path set.
>
>
> I don't know anybody that uses WebWare to be honest so I think it'd be safe to
> just drop that WebKit cruft from Servlet.py, or I could just incorporate your
> hack around it :P

As one of the few people that still uses WebWare in production (legacy app 
in maintenance mode ...), I think you could go ahead and drop it.


>>
>> On 28/01/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 =3D=3D 'darwin' and not 'WebKit' in sys.modules:
>>         module =3D type(sys)
>>         sys.modules['WebKit'] =3D 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
> Cheers,
> -R. Tyler Ballance
> --------------------------------------
> Jabber: [email protected]
> GitHub: http://github.com/rtyler
> Twitter: http://twitter.com/agentdero
>   Blog: http://unethicalblogger.com
>
>

------------------------------------------------------------------------------
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