<s> from weblab . core . coordinator . clients . weblabdeusto import WebLabDeustoClient <EOL> import os <EOL> import time <EOL> from weblab . core . reservations import WaitingReservation , ConfirmedReservation , WaitingConfirmationReservation <EOL> from weblab . data . command import Command <EOL> from weblab . data . experiments import ExperimentId <EOL> import threading <EOL> import config <EOL> threads = { } <EOL> users_in = <NUM_LIT:0> <EOL> def user_t ( ) : <EOL> do_full_experiment_use ( ) <EOL> def main ( ) : <EOL> print "<STR_LIT>" <EOL> for i in range ( config . NUM_USERS ) : <EOL> t = threading . Thread ( None , user_t ) <EOL> threads [ t ] = t <EOL> t . start ( ) <EOL> print "<STR_LIT>" <EOL> while True : <EOL> print "<STR_LIT>" % users_in <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> for t in threads . values ( ) : <EOL> if t . is_alive ( ) : break <EOL> else : <EOL> break <EOL> print "<STR_LIT>" <EOL> def do_full_experiment_use ( ) : <EOL> """<STR_LIT>""" <EOL> wc = WebLabDeustoClient ( config . WEBLAB_BASE_URL ) <EOL> sessionid = wc . login ( config . LOGIN , config . PASSWORD ) <EOL> if not sessionid : raise Exception ( "<STR_LIT>" ) <EOL> experiment_id = ExperimentId ( config . EXP_NAME , config . EXP_CATEGORY ) <EOL> waiting = wc . reserve_experiment ( sessionid , experiment_id , "<STR_LIT:{}>" , "<STR_LIT:{}>" , None ) <EOL> reservation_id = waiting . reservation_id <EOL> while True : <EOL> status = wc . get_reservation_status ( reservation_id ) <EOL> if type ( status ) is WaitingReservation : <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> elif type ( status ) is ConfirmedReservation : <EOL> break <EOL> elif type ( status ) is WaitingConfirmationReservation : <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> global users_in <EOL> users_in += <NUM_LIT:1> <EOL> for i in range ( config . COMMANDS_PER_USER ) : <EOL> cmd = Command ( config . COMMAND ) <EOL> result = wc . send_command ( reservation_id , cmd ) <EOL> if not result . commandstring . startswith ( "<STR_LIT>" ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> time . sleep ( config . TIME_BETWEEN_COMMANDS ) <EOL> users_in -= <NUM_LIT:1> <EOL> result = wc . logout ( sessionid ) <EOL> print "<STR_LIT>" % result <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
