[python-win32] Reload Python libraries to ASP script engine

Mark Hammond mhammond at skippinet.com.au
Tue Jul 27 09:11:10 CEST 2004


> After doing this, my newly installed Python library code is run.
> I assume this causes any Python script engine to exit and a new
> Python script engine to be started at the next ASP reference.
>
> Are there other ways to get Python library code loaded?

Remember that inside ASP, you just have a simple Python environment.  So the
issues you face are identical to what python.exe faces.  Thus, the problem
you describe can happen in one of 2 ways:
* You already had an imported module of the same name as the new one.
* the newly installed modules relied on a sys.path change.
A third way would be something I haven't thought of :)

So, consider these problems as if you were facing them from python.exe and
didn't want to shut it down.  For the 2 secnarios above, you would need
either an explicit "reload()", or a runtime modification to sys.path.

So one option would be a private page with a multi-line edit control, and
your ASP code could simply execute this code (via "exec").  In this form you
could enter a statement like:
"""
import foo
reload(foo)
"""
or maybe:
"""
import sys
sys.path.append("c:\\mydir")
"""
and the foo module will be reloaded for the entire process.  There are other
ways you could tackle this too.  Unfortunately, exactly what you do will
probably depend on your app, so providing any kind of generic
"reload_libraries" command is not practical.

I hope that makes sense.

Mark.



More information about the Python-win32 mailing list