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

# Source Code for Module Products.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 or (at your
     8  # option) any later version as published by the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13  from threading import Thread
    14
    15 -class ZenZopeThread(Thread):
    16      """
    17      Thread running inside zope that has its own read-only connection to the db.
    18      """
    19
    20 -    def __init__(self):
    21          Thread.__init__(self)
    22          self.setDaemon(1)
    23
    24
    25 -    def opendb(self):
    26          """Open a connection to the zope database.
    27          """
    28          from Zope2 import DB
    29          self.conn = DB.open()
    30          root = self.conn.root()
    31          self.app  = root['Application']
    32
    33
    34 -    def syncdb(self):
    35          """Sync the connection to the zope database.
    36          """
    37          self.conn.sync()
    38
    39
    40 -    def closedb(self):
    41          """Abort our transaction (we are read-only) and close connection.
    42          """
    43          try:
    44              import transaction
    45              transaction.abort()
    46              self.conn.close()
    47          except:
    48              pass
    49