>This isn't thread-safe -- 2 servlets could create the store at the same
time.
>
>You're better off putting the store initialization into a module that gets 
>imported -- then Python automatically ensures that only one thread imports 
>it at once.  (Either that or you should explicitly use a threading.Lock 
>object to make it thread-safe.)
>
>If you want to "pre-load" the store when the app server starts up to reduce

>response time, then you can put the import into the __init__.py in your 
>context directory.  __init__.py automatically gets imported when the app 
>server starts.

Thanks Geoff for your hint concerning thread-safety. But Ian's way to have a
Base
Servlet that cares for store opening is attractive too. Do you think, that
one can
mix both methods by having a store initialization module that gets imported
in
a base servlet:

# MyObjectStore.py
from MiddleKit.Run.MySQLObjectStore import MySQLObjectStore
store = MySQLObjectStore()
store.readModelFileNamed('MyMiddleKitModel')


# MyPage.py
from MyObjectStore import store
from WebKit.Page import Page
class MyPage(Page):
     def Store(self):
         return store

# MyDerivedPage.py
from MyPage import MyPage
class MyDerivedPage(MyPage):
        def writeContent(self):
                currentStore = self.Store()
                # do something with currentStore

Is the above code thread-save.


Joern.
                

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to