-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.py
More file actions
executable file
·60 lines (48 loc) · 1.2 KB
/
simulator.py
File metadata and controls
executable file
·60 lines (48 loc) · 1.2 KB
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
60
#!/usr/bin/env python
##
# simulator.py -
# Module for driving the Trip generator.
##
from __future__ import absolute_import
import sys
import time
import redis
from tripgrid.Trip import *
g_resetDB = True
g_debugLevel = 1
def initRedis():
r = redis.Redis()
dbsize = r.dbsize()
itr = 0
while dbsize != 0:
r.flushall()
dbsize = r.dbsize()
itr += 1
# print "iterations to flush redis: %d", itr
def log(loglevel, *args):
if loglevel <= g_debugLevel:
print args
def main():
if g_resetDB:
initRedis()
numTrips = 500
trips = []
while True:
log(3, "adding %d trips" % (numTrips))
for x in range(0, numTrips):
trip = Trip()
trip.start()
trips.append(trip)
log(1, "trips running: ", len(trips))
# wait for the first trip to end to give the trips
# some time to run.
now = time.time()
trips[0].join()
log(5, "first trip ended in %d seconds" % (time.time() - now))
numTrips = 0
for trip in trips:
if trip.ended():
numTrips += 1
trips.remove(trip)
if __name__ == "__main__":
main()