Python Specials #12 Single-Server Queueing System Simulation

Опубликовано: 23 Март 2026
на канале: Coder & Maker
1,013
12

This code defines a SingleServerQueue class which represents the server in the queueing system. The server has a capacity of 1 and is represented by a simpy.Resource object. The service time is passed in as a parameter to the constructor.

The customer_arrivals function generates customer arrivals using an exponential distribution with a mean of 5. For each arrival, a new customer process is started using the customer function.

The customer function requests access to the server resource, waits until it is available, then serves the customer for a random amount of time using an exponential distribution with a mean equal to the service time. After being served, the customer leaves the queueing system.

The simulation is started by creating a simpy.Environment object and calling customer_arrivals as a process. The simulation runs until SIM_TIME (in this case, 1000). During the simulation, the arrival and departure of each customer are printed to the console.

Thanks for watching. For more videos and to support us, you can subscribe and follow our channel. Good luck...

All Coder & Maker videos :    • ALL VIDEOS  
More Python Special videos:    • Python Specials  
More Python Examples videos:    • Python Examples  
Python Basics Videos :    • Python Basics  
Python Turtle Graphics Module:    • Python Turtle  Graphics  
Python Matplotlib Module Tutorials:    • Python Matplotlib Module  
Python Numpy Module Tutorials:    • Python Numpy Module  
Python Random Module Tutorials:    • Python Random Module  
Python Thonny Graphics Tutorials:    • Python Turtle Tutorials  


Download Thonny Ide: https://thonny.org