-
Notifications
You must be signed in to change notification settings - Fork 0
/
timServer.py
39 lines (31 loc) · 1018 Bytes
/
timServer.py
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
#!/usr/bin/env python
'''
Nick Warren - #201404779
Concurrent Programming Assignment #2
ServerStation for TimQueue
Server capable of serviging a single customer at a time
'''
import random
from threading import Thread
class ServerStation(Thread):
def __init__(self, timQueue):
''' Constructor. '''
self.active = True
self.lineup = timQueue.lineup
self.busy = False
self.clock = timQueue.clock
Thread.__init__(self)
def run(self):
while(self.active) :
currentCustomer = self.lineup.get()
print("Serving customer")
self.busy = True
timeStartedJob = self.clock.timeSinceInit
randNum = random.randint(120,601)
timeFinishJob = timeStartedJob + randNum
while(self.clock.timeSinceInit < timeFinishJob):
pass
currentCustomer.customerServed(timeFinishJob)
self.busy = False
def closeShop(self):
self.active = False