DESCRIPTION Students: Please keep in mind the OMSI rules. Save your files often, make sure OMSI fills your entire screen at all times, etc. Remember that clicking CopyQtoA will copy the entire question box to the answer box. In questions involving code which will PARTIALLY be given to you in the question specs, you may need add new lines. There may not be information given as to where the lines should be inserted. MAKE SURE TO RUN THE CODE IN PROBLEMS THAT INVOLVE CODE! QUESTION (20 pts) Fill in the blank with Python terminology: The second argument of activate() is a/an _____________________. QUESTION (20 pts) Fill in the blanks: In SimPy, a thread's turn ends when _____________________. With Python threads, a thread's turn ends when either _______________________ or ________________________. QUESTION (20 pts) Consider the server code on pp.91-92. In some cases, omission of a line (individually) would result in the program running forever. State the line numbers of such lines. (List them in ascending numerical order, please.) QUESTION -ext .py -run 'python omsi_answer4.py' (40 pts) Add code to the machine repair SimPy example so that it prints out the mean down time. For full credit, modify only code in main(). (Note our point that "the leftover actions" near the end of the simulation don't matter.) from SimPy.Simulation import * from random import Random,expovariate,uniform class G: Rnd = Random(12345) RepairPerson = Resource(1) class MachineClass(Process): TotalUpTime = 0.0 NRep = 0 NImmedRep = 0 UpRate = 1/1.0 RepairRate = 1/0.5 NextID = 0 NUp = 0 def __init__(self): Process.__init__(self) self.StartUpTime = 0.0 self.ID = MachineClass.NextID MachineClass.NextID += 1 MachineClass.NUp += 1 def Run(self): while 1: self.StartUpTime = now() yield hold,self,G.Rnd.expovariate(MachineClass.UpRate) MachineClass.TotalUpTime += now() - self.StartUpTime MachineClass.NRep += 1 if G.RepairPerson.n == 1: MachineClass.NImmedRep += 1 yield request,self,G.RepairPerson yield hold,self,G.Rnd.expovariate(MachineClass.RepairRate) yield release,self,G.RepairPerson def main(): initialize() for I in range(2): M = MachineClass() activate(M,M.Run()) MaxSimtime = 10000.0 simulate(until=MaxSimtime) if __name__ == '__main__': main()