/usr/share/doc/pyro/examples/stresstest/producer.py is in pyro-examples 1:3.14-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #!/usr/bin/env python
from Pyro.EventService.Clients import Publisher
from Pyro.errors import NamingError
import random, time
from threading import Thread
mustStop=0
class VehicleProducer(Publisher, Thread):
directions = ('north','east','south','west')
cars = ('Ford','Toyota','Chrysler','Vauxhall','Honda','BMW')
colors = ('red','green','white','black','blue','yellow')
def __init__(self,id):
Publisher.__init__(self)
Thread.__init__(self)
self.id=id
def nextVehicle(self):
direction=random.choice(self.directions)
car=random.choice(self.cars)
color=random.choice(self.colors)
self.publish('STRESSTEST.CARS.HEADING.'+direction, (color,car))
print self.id,'published'
def run(self):
print 'Producer running.'
try:
global mustStop
while not mustStop:
time.sleep(random.random()/10)
self.nextVehicle()
print 'Producer stopped.'
except NamingError:
print 'Cannot find service. Is the Event Service running?'
def main():
threads=[]
for i in range(10):
vp=VehicleProducer(i)
vp.start()
threads.append(vp)
try:
while 1:
time.sleep(10)
except KeyboardInterrupt:
global mustStop
mustStop=1
print 'Break-- waiting for threads to stop.'
for vp in threads:
vp.join()
if __name__=='__main__':
main()
|