On Fri, 2003-01-31 at 12:31, Fionn Behrens wrote:
> I have created a simple "index.psp" drop-in page along with a Page Class
> descendant Servlet which works nicely to automatically thumbnail-index,
> resize and optionally logo-ize all pictures that are in its folder.
> 
> I have one problem left, however. 
> 
> Since I want to keep this rather simple I dont want to use a database
> for data associated to the pictures. So I added a prefs attribute to the
> Servlet. But since prefs must be written to disk at some point there
> will be problems if several instances of my servlet are being created,
> writing their stuff to disk simultaneously.

You can still put it in a global, but you need to do locking to handle
this.  I'd personally use a combination of my own ParamFactory and
Persist modules, which are primitive but effective.  I think it would go
something like:

class _Image(PersistMixin):

    def __init__(self, filename):
        self._filename = filename
        self._size, self._description = self.load(autoCommit=1)
        # later, if you ever change self._size or self._description,
        # you must call self.changed() so save those values.

    def data(self):
        return self._size, self._description

    def filename(self):
        return os.path.join('/path/to/metadata', 
                            self._filename + ".pickle")

Image = ParamFactory(_Image)


ParamFactory will make sure there's only one instance of any particular
_Image for any filename -- this simplifies a lot of concurrency issues. 
The PersistMixin saves that data to a file.
        
Maybe I'll document these better sometime and put them into MiscUtils,
since they are useful for concurrent threads and simple persistence,
which are common things to do in Webware.  But until then you can find
these modules at:

http://colorstudy.com/software/python/Persist.py
http://colorstudy.com/software/python/ParamFactory.py

-- 
Ian Bicking           Colorstudy Web Development
[EMAIL PROTECTED]   http://www.colorstudy.com
PGP: gpg --keyserver pgp.mit.edu --recv-keys 0x9B9E28B7
4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to