Ejemplo n.º 1
0
Archivo: engine.py Proyecto: happz/hlib
  def on_thread_start(self, e):
    """
    Default hlib handler for C{engine.ThreadStarted} event.

    Set up thread enviroment (L{hruntime} variables) and open database connection.

    @type e:			L{events.engine.ThreadStarted}
    @param e:			Current event.
    """

    hruntime.reset_locals()

    hruntime.app = e.server.app
    hruntime.db = e.server.app.db
    hruntime.root = e.server.app.root

    thread_stats_setter = functools.partial(STATS.set, hruntime.service_server.pool.stats_name, 'Threads', hruntime.tid)
    thread_stats_setter('Total bytes read', 0)
    thread_stats_setter('Total bytes written', 0)
    thread_stats_setter('Total requests', 0)
    thread_stats_setter('Total time', 0)

    dbconn, dbroot = hruntime.db.connect()
    hruntime.db.start_transaction()

    hruntime.dbconn = dbconn
    hruntime.dbroot = dbroot

    if 'root' in dbroot:
      hruntime.dbroot = dbroot['root']
      hruntime.db.rollback()
Ejemplo n.º 2
0
 def test_reset(self):
   for p in hruntime.RESET_PROPERTIES:
     setattr(hruntime, p, True)
   hruntime.reset_locals()
   for p in hruntime.RESET_PROPERTIES:
     if p in ('time', 'localtime'):
       ANY(getattr(hruntime, p))
     else:
       NONE(getattr(hruntime, p))