-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
40 lines (32 loc) · 1.11 KB
/
main.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
40
from light import Light
from junction import Junction
from setup import mainSetup
from Vehicle import Vehicle
from TrafficLightController import TrafficLightController
import threading
import time
import random
import multiprocessing
class Main():
def __init__(self) -> None:
mainSetup()
trafficLightController = TrafficLightController()
for junction in Junction.junctions:
thread = threading.Thread(target=trafficLightController.controller, args=(junction,))
thread.daemon = True
thread.start()
vehicleGeneration = multiprocessing.Process(target=self.generateVehicles())
vehicleGeneration.start()
while True:
time.sleep(30)
#create thread for generating vehicles
def generateVehicles(self) -> None:
while True:
randint = random.randint(0, 3)
for i in range(randint):
vehicle = Vehicle()
vehicle.enterNextJunction()
randSleep = random.randint(2, 4)
time.sleep(randSleep)
if __name__ == "__main__":
main = Main()