[mod_python] Single import at startup

Nick nick at dd.revealed.net
Wed Sep 14 15:07:32 EDT 2005


If the import is huge, it can create a significant delay (between the 
initiation of the request and the fulfillment of that request) on the 
first call of a handler.  If you have multiple server children, then 
there is that delay for each child.

Nick

Nicolas Lehuen wrote:
> Why not use import in the handler code or the published module ? AFAIK 
> this should import the module only once per interpreter. I don't 
> understand the advantage of importing a module as soon as the 
> interpreter is created vs importing the module when it is needed (i.e. 
> in the handler module or published page). Performance-wise, to me, both 
> ways are similar, and the second has the benefit of actually working :).
> 
> Regards,
> Nicolas
> 
> 2005/9/14, Scott Chapman <scott_list at mischko.com 
> <mailto:scott_list at mischko.com>>:
> 
>     Lee Brown wrote:
> 
>      > I agree with you that doing an import once at server startup
>     rather than at
>      > each request seems like a cleaner way to go.  The only drawback
>     is that if
>      > you change the code in the imported module you'll have to
>     re-start the
>      > server but this usually isn't a problem for many applications.
> 
>     It is my understanding that importing once at startup is problematic
>     because the
>     only hook to do it is _before_ the interpreter is established?
> 
>     I'd like to suggest that mod_python be modified in the next(?)
>     version to enable
>       a hook for importing after the interpreter is established.  This
>     would become
>     the default place to connect to the database with persistent
>     connection, etc. as
>     well.  I think mod_perl supports this more "intuitively".
> 
>     If anyone has found a clean way to do this stuff in the existing
>     environment,
>     please educate! :)
> 
>     Scott
>     _______________________________________________
>     Mod_python mailing list
>     Mod_python at modpython.org <mailto:Mod_python at modpython.org>
>     http://mailman.modpython.org/mailman/listinfo/mod_python
>     <http://mailman.modpython.org/mailman/listinfo/mod_python>
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python


More information about the Mod_python mailing list