Package Products :: Package ZenUtils :: Module ZenZopeThread
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenUtils.ZenZopeThread

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
 4  #  
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 7  #  
 8  ############################################################################## 
 9   
10   
11  from threading import Thread 
12   
13 -class ZenZopeThread(Thread):
14 """ 15 Thread running inside zope that has its own read-only connection to the db. 16 """ 17
18 - def __init__(self):
19 Thread.__init__(self) 20 self.setDaemon(1)
21 22
23 - def opendb(self):
24 """Open a connection to the zope database. 25 """ 26 from Zope2 import DB 27 self.conn = DB.open() 28 root = self.conn.root() 29 self.app = root['Application']
30 31
32 - def syncdb(self):
33 """Sync the connection to the zope database. 34 """ 35 self.conn.sync()
36 37
38 - def closedb(self):
39 """Abort our transaction (we are read-only) and close connection. 40 """ 41 try: 42 import transaction 43 transaction.abort() 44 self.conn.close() 45 except: 46 pass
47