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

Source Code for Module ZenUtils.ZenZopeThread

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13  import logging 
14  from threading import Thread 
15   
16 -class ZenZopeThread(Thread):
17 """ 18 Thread running inside zope that has its own read-only connection to the db. 19 """ 20
21 - def __init__(self):
22 Thread.__init__(self) 23 self.setDaemon(1)
24 25
26 - def opendb(self):
27 """Open a connection to the zope database. 28 """ 29 from Zope2 import DB 30 self.conn = DB.open() 31 root = self.conn.root() 32 self.app = root['Application']
33 34
35 - def syncdb(self):
36 """Sync the connection to the zope database. 37 """ 38 self.conn.sync()
39 40
41 - def closedb(self):
42 """Abort our transaction (we are read-only) and close connection. 43 """ 44 try: 45 import transaction 46 transaction.abort() 47 self.conn.close() 48 except: 49 pass
50