def simu(options): itera = 0 ################################# # Begin simu if(options.reset): if(not prims.initDb()): raise util.SimuException("Market is not opened") begin = util.getAvct(None) with util.DbConn(const) as dbcon: with util.DbCursor(dbcon) as cursor: util.writeMaxOptions(cursor,options) for user in util.nameUsers(): prims.createUser(cursor,user) if(options.CHECKQUALITYOWNERSHIP): util.setQualityOwnership(cursor,True) ################################## if((not scenarii.threadAllowed(options.scenario)) and options.threads>1): raise Exception("This scenario cannot be run in thread") _begin = util.now() if(options.threads==1): user = util.nameUser(0) scenarii.simuInt((options,user)) else: # run in theads ts = [] for i in range(options.threads): user = util.nameUser(i) t = threa.ThreadWithArgs(func=scenarii.simuInt,args=(options,user),name=user) t.start() ts.append(t) for t in ts: t.join() itera = options.iteration * options.threads duree = util.duree(_begin,util.now()) ################################## # Terminate simu terminate(begin,duree,itera,options) return
def terminate(begin,duree,itera,options): if(itera): res = util.getAvct(begin) res['dureeSecs'] = int(duree) res['nbOper'] = itera prims.storeOptions('results',res) prims.storeOptions('options',util.getDictInt(options)) print '%i oper terminated after %.6f seconds (%.6f secs/oper)' % (itera,duree,duree/itera) with util.DbConn(const) as dbcon: with util.DbCursor(dbcon) as cursor: verifyVolumes(cursor) if options.maxparams: print "max_options:%s " % (util.readMaxOptions(cursor),) if(options.verif): util.runverif(cursor) return