Re: Metakit DB Synchronizing (Python)

Brian Kelley <[email protected]>
Newsgroups gmane.comp.db.metakit
Message-ID <[email protected]>
I don't seem to have this problem.  Attached is some simple test code,
two threads are started, one thread modifies the view and one thread
just calls metakit.dump on the view.  Take a look and see if you are
doing anything drastically different:

import time, threading, whrandom
import metakit
st = metakit.storage()
vw = st.getas("test[a,b,c]")
for i in range(10):
   vw.append(("%ia"%i, "%ib"%i, "%ic"%i))

class MyThread(threading.Thread):
   def __init__(self, st, alter=False):
       threading.Thread.__init__(self)
       self.vw = st.view("test")
       self.alter = alter

   def run(self):
       iterations = 10
       count = 1000
       for i in range(iterations):
           if self.alter:
               for i in range(len(self.vw)):
                   self.vw[i].a = str(count)
               count += 1
           else:
               metakit.dump(self.vw)
           time.sleep(1)
       print self.getName(), "is DONE"

if __name__ == '__main__':
   threadList = []

   # Create 5 MyThread() threads
   threadList.append(MyThread(st, alter=True))
   threadList.append(MyThread(st, alter=False))

   # Start all threads
   for thread in threadList:
       thread.start()

   # As long as we have more than just the 'main' thread running, print
   # out a status message
   while threading.activeCount() > 1 :
       print str(threading.activeCount()), "threads running incl. main"
       time.sleep(1)
_____________________________________________
Metakit mailing list  -  [email protected]
http://www.equi4.com/mailman/listinfo/metakit
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.