Funny you should mention this method of using lockfile objects, that is
exactly the model we are going to use here to solve the problem.  I'll let
you know if it works for us

Jose

 -------- Original Message --------
   Subject: RE: [Webware-discuss] At a loss please help with Sessions and
Tasks
   From: Roger Haase <[EMAIL PROTECTED]>
   Date: Thu, May 29, 2003 7:42 am
   To: jose <[EMAIL PROTECTED]>, [EMAIL PROTECTED]


   --- jose <[EMAIL PROTECTED]> wrote:
   > Exclent point, Here is what I need to do, I have a web application
   > which
   > allows users to interact with a flash object on a web page.  Now for
   > the
   > problem the flash object writes an XML file to the server (I didn't
   > make
   > the flash object so I don't have control of this object), so I need
   > to
   > make sure that only one person has access to the object at any given
   > moment.

   I had a roughly similar problem, wanting to control one-at-a-time
   access to a logical chunk of several MySQL tables. Along the way, I
   also implemented a mechanism to limit the number of simultaneous
   users. I did this by adding lock objects and dictionaries at the
   module level of my SitePage.

   After getting a little help here, I was able to add a feature to
   pickle the state of these dictionaries and reload them when my
   SitePage was reloaded (very helpful during testing). Your locks will
   be different than mine, but here is my SitePage module level code to
   pickle and unpickle my  the dictionaries I use to control access
   (spActiveUsers,spActiveFolders,spActiveUerTimeout dictionaries and
   associated locks are defined elsewhere and not shown):

   # variables used to preserve state across restarts
   spSaveState = 1
   spPickleFileName = 'PickledState.dra'
   file = spConfigs['baseDirectory'] + spPickleFileName
   # get previous state if there is one
   try:
       pFile = open(file,'r')
       spActiveUsers,spActiveFolders,spActiveUserTimeout =
   cPickle.load(pFile)
       pFile.close()
   except:
       pass

   # special function to save module state in case of a restart
   def saveState():
       '''Pickle key fields and write to disk.'''
       file = spConfigs['baseDirectory'] + spPickleFileName
       pFile = open(file,'w')
   cPickle.dump((spActiveUsers,spActiveFolders,spActiveUserTimeout),pFile)
       pFile.close()


   Then within my logon process, I have a small bit of code that gets
   executed the first time someone logs on. "saveState" will get called
   when the AppServer is restarted.

           #one time only, set means of saving global variables
           global spSaveState
           if spSaveState:
               spSaveState = 0
               self.application().addShutDownHandler(saveState)

   HTH,

   Roger Haase

   __________________________________
   Do you Yahoo!?
   Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
   http://calendar.yahoo.com





-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to