Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threading question
#1
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Concurrent futures threading running at same speed as non-threading billykid999 13 1,716 May-03-2023, 08:22 AM
Last Post: billykid999
  Tutorials on sockets, threading and multi-threading? muzikman 2 2,076 Oct-01-2021, 08:32 PM
Last Post: muzikman
  Newb Question - Threading in Crons vvarrior 2 2,718 Jul-20-2018, 08:12 PM
Last Post: vvarrior

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020