Hi all,

After some effort I've been able to understand a bug which has been causing
me problems, but I don't know the best way to fix it.  

In brief, it is possible for Webware to reload a servlet module, which can
cause problems for instances whose classes get reloaded under their feet.

I've reduced the problem to a small test case, consisting of two servlets, X
and Y.  X is a subclass of Y.

- X.py -----------------------------------
from Y import Y
 
class X(Y):
    def writeContent(self):
        self.writeln('This is X<br>')
        print 'X is %r' % X
        print 'Y is %r' % Y
        self.doSomething()
        self.writeln('<a href="Y">Go to Y.</a>')
 
    def doSomething(self):
        assert isinstance(self, X)
        assert isinstance(self, Y)
        Y.doSomething(self)

- Y.py ------------------------------------
from WebKit.Page import Page
 
class Y(Page):
    def writeContent(self):
        self.writeln('This is Y<br>')
        print 'Y is %r' % Y
        assert isinstance(self, Y)
        self.writeln('<a href="X">Go back to X.</a>')
 
    def doSomething(self):
        assert isinstance(self, Y)
-------------------------------------------------

Now if you start Webware, visit servlet X, then Y, and then X, you get
an assertion error (if you visit Y first there are no problems, so you can
get an idea for how easy it was to find the cause of this bug):

  File "MyContext/Y.py", line 11, in doSomething
    assert isinstance(self, Y)

What's happening is when you visit X, the Y module is imported into python.
Then you visit Y, but the servlet class cache doesn't yet contain Y, so it
tries to load it.  It _should_ find the module in sys.modules, but 
ServletFactory._importModuleFromDirectory() is being called with 
'forceReload=1', and so it is getting reloaded.  

There seems to be a reason forceReload was added to the code, as the
following comment alludes (ServletFactory, line 308), but I don't really
understand the context.

# Finally, import the module itself as though it was part of the package
# or subpackage, even though it may be located somewhere else.

Geoff, from the CVS logs it looks like you added forceReload.  Do you
remember the circumstances under which reloading the module was necessary?
Can you shed some light on the code in question?

--
Jason D. Hildebrand
[EMAIL PROTECTED]



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-devel

Reply via email to