We discussed this issue in private, but I thought to respond to the list
so that others will benefit. My reply is embedded in the message.
On Thu, 20 Feb 2003, Steven D. Arnold wrote:
>On 2/20/03 9:22 PM, "Steven D. Arnold" <stevena@...> wrote:
>> I may be having some serious misconceptions about how session works, but I
>> wonder if anyone can point out the mistake(s) I'm making here. I've tried
>> to reduce the problem to the minimum amount of code possible.
>I've figured out a workable solution to this issue. A couple things
>1. A cookie doesn't get set unless the entire page processes successfully
>(which makes sense). That was the basic reason my sample code failed;
>the code never completely ran because of the KeyError, hence the cookie
>was never set.
Perhaps you are running into a bug, but this should NOT be the case. The
Spyce interface to modules is well specified. Specifically, the start()
method is called before processing. And the finish() method is called
after processing. Even if an exception occurs during the processing the
finish() will still get called. In fact, if an exception occurs during
processing then you will get that exception as the error parameter to the
finish() method, and for 'normal' processing this variable will be None.
Search for a line in spyce.py with the following content:
You'll see that it sits in the finally clause of the try-catch block that
'thespyce' is an instance of a spyceWrapper. If you look at the
spyceDestroy method, you'll find the calls to the finish() method of each
of the loaded modules. So, it should always get called. If this is not the
behaviour that you are seeing, please let me know. The documentation
example docs/examples/error.spy explicitly tests this functionality. It is
used by the implicitly loaded error module to provide error-handling
functionality to the Spyce user.
>2. If you make changes to a session, you must save the changes using
>session.set or it won't save; this sort of thing is lost across
>redirects, internal or external. It makes me wish for a feature like the
>ability to have a function always run whenever a page is done, before any
>redirects are processed. One thing this function would do for me is save
This already exists, as discussed above. The automatic session saving is
performed in the finish() method of the session module. It should ALWAYS
get called, whether an exception was raised during processing or not.
All the best,