Threading question - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Threading question (/thread-27791.html) |
Threading question - DPaul - Jun-22-2020 I'm into waiting lines. (Yes i know there are formulas and ready made modules available) I imagine a bakery with random client arrivals (between x and y seconds) This makes a queue which i can monitor every 5 seconds with the code below (that works.) question 1: does this code look solid = python compliant ? The queue will (later) be depleted by 1,2 or 3 personnel servicing te clients,each finishing in random a to b seconds. question 2: can i start a second threading class (personnel) within the same __main__ (not interfering with my arrivals thread)? queue = 0 class arrivals(threading.Thread): def run(self): global queue while True: secs = random.randint(5,10) time.sleep(secs) queue += 1 myClients = arrivals() myClients.start() while True: print(queue) time.sleep(5)thx, Paul |