naming.py :  » Database » Python-Remote-Objects » Pyro-3.10 » examples » stresstest » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » Python Remote Objects 
Python Remote Objects » Pyro 3.10 » examples » stresstest » naming.py
#!/usr/bin/env python

import Pyro.naming
import random, time
from threading import Thread
import random
from Pyro.errors import NamingError
import binascii

mustStop=0

def name():
  return str(random.random())[-3:]

def nameG():
  if random.random()>0.3:
    return 'trasher.G'+name()+'.'+name()
  else:
    return 'trasher.'+name()
  

class NamingTrasher(Thread):
  def __init__(self,number):
    Thread.__init__(self)
    self.number=number

  def flatlist(self):
    if random.random()>0.8:
      try:
        a=len(self.ns.flatlist())
      except NamingError,x:
        pass
  def register(self):
    for i in range(4):
      try:
        self.ns.register(nameG(),'PYRO://localhost/111111111')
      except NamingError,x:
        pass
  def remove(self):
    try:
      self.ns.unregister(nameG())
    except NamingError,x:
      pass
  def resolve(self):
    try:
      uri=self.ns.resolve(nameG())
    except NamingError,x:
      pass
  def creategrp(self):
    for i in range(3):
      try:
        self.ns.createGroup('trasher.G'+name())
      except NamingError,x:
        pass
  def delgrp(self):
    if random.random()>0.8:
      try:
        self.ns.deleteGroup('trasher.G'+name())
      except NamingError,x:
        pass

  def run(self):  
    self.ns = Pyro.naming.NameServerLocator().getNS()
    print 'Name Server trasher running.'
    while not mustStop:
      random.choice((self.flatlist, self.register, self.remove, self.resolve, self.creategrp, self.delgrp)) ()
      print self.number,'called'
      time.sleep(random.random()/10)
    print 'Trasher exiting.'  

def main():
  Pyro.core.initClient()
  threads=[]
  ns = Pyro.naming.NameServerLocator().getNS()
  ns.createGroup('trasher')
  for i in range(10):
    nt=NamingTrasher(i)
    nt.start()
    threads.append(nt)

  try:
    while 1:
      time.sleep(10)
  except KeyboardInterrupt:
    global mustStop
    mustStop=1

  print 'Break-- waiting for threads to stop.'
  for nt in threads:
    nt.join()
  ns.deleteGroup('trasher')

if __name__=='__main__':
  main()

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.