On 4/13/03 9:42 PM, "Steven D. Arnold" <stevena@...> wrote:
> I set my python path in a Spyce file called environ_setup.spy, which is
> loaded by a header file that is included in all my Spyce pages. Almost all
> the time, this works great. However, when I try to load the session.py
> module, it consistently generates an exception when trying to unpickle one
> of my objects, saying that it can't find the module. Obviously the
> session.py module is not seeing the PYTHONPATH environment variable, even
> though this is clearly set before I load the session module. (I tried doing
> this both by inserting into sys.path, and by setting PYTHONPATH in
> I can't set this as a global apache environment variable, because I have
> multiple applications running on the same server that use a different set of
> modules in the same namespace. Hence, if I point both applications to
> either my "neo" modules directory, or to the other application's neo
> directory, one or the other of us will be using the wrong modules.
> What is the correct way to set the PYTHONPATH, on a per-application basis,
> so that loaded modules such as session.py see them?
In answer to my own question, one way to do this -- note this is conjecture,
I haven't actually done it yet -- is to write your own session handling
module based on one of the modules provided in the Spyce package. It could
include whatever PYTHONPATH info you wanted, including looking it up from a
config file etc. It could even inherit (I imagine) from one of the existing
session-handling classes so that the code doesn't have to be re-written.
I think it would be a lot simpler for people new to Spyce if one could
specify an init function that the session-handling class would run. This
could be an optional parameter to the default session-handling classes.
Rimon, if you have an interest in this and would consider incorporating such
a feature, I could code it up and send you a patch. If you have a different
idea for how to do such a thing, let me know and I'd probably be willing to
write that as well, unless you'd rather do it yourself.
Having said all that, note this is not a general solution to the problem of
setting environment on imported Spyce modules, such as PYTHONPATH. So far
the only module I care about is session, but that could change in the future
as people increasingly explore the power of Spyce modules.