Queue size appears to be the ENV size in SimPy
<p>I am just starting to work on an event simulation, and I am having some issues with monitoring the queue.</p>

<p>It appears that everytime I check the queue, it is actually showing the Env.now.  Any advice?</p>

<pre><code>import simpy

num_of_machines = 2

env = simpy.Environment()
bcs = simpy.Resource(env, capacity=num_of_machines)

def monitor(resource):
     """This is our monitoring callback."""

     print('Queue size: %s' % len(resource.queue))

def process_client(env, name):

    with bcs.request() as req:
        yield req
        print('%s starting to charge at %s' % (name, env.now))
        yield env.timeout(90)
        print('%s ending charge at %s' % (name, env.now))
        monitor(bcs)



def setup(env):
    i = 0

    while True:
        i += 1
        yield env.timeout(1)

        env.process(process_client(env, ('Car %s' % i)))

env.process(setup(env))

env.run(until=300)
</code></pre>

<p>Results:</p>

<pre><code>Car 1 starting to charge at 1
Car 2 starting to charge at 2
Car 1 ending charge at 91
Queue size: 88
Car 3 starting to charge at 91
Car 2 ending charge at 92
Queue size: 88
Car 4 starting to charge at 92
Car 3 ending charge at 181
Queue size: 176
Car 5 starting to charge at 181
Car 4 ending charge at 182
Queue size: 176
Car 6 starting to charge at 182
Car 5 ending charge at 271
Queue size: 264
Car 7 starting to charge at 271
Car 6 ending charge at 272
Queue size: 264
Car 8 starting to charge at 272
</code></pre>

<p>You spawn a <code>process_client()</code> every timestep, so when the first of these processes is done after 90 time steps, you already have created 90 new processes that are queueing up.  So your numbers are looking quite right.</p>

python simpy