T Wengert
T Wengert

Reputation: 31

simpy Requests piling up in queue

I am simulating meetings in conference rooms and I started with the Bank Renege example as a model. It is working as intended - this first version just tries to put 5 meetings into 3 rooms in several different hours. HOWEVER, I notice that the queued requests (those who don't get a conference room) accumulate in the Resource.queue list. Shouldn't they release and disappear? Is this an error on my part? I have tried
req.cancel simpy.Interrupt and a few other attempts, to no effect that I can tell.

RANDOM_SEED = 181106
NbrMtgs = 5  # Total number of meetings in a period
INTERVAL = 1.0  # Generate new meetings every x hours

def Schedule(env, NbrMtgs, interval, ResRooms):
    #Source generates meetings
    while True:
        for i in range(NbrMtgs):
            h=env.now
            m = Meet(env, 'Meeting%02d_%02d' % (h,i), ResRooms, TimeInMtg=MtgLen)
            env.process(m)
        t = 1
        yield env.timeout(t)

def Meet(env, name, ResRooms, TimeInMtg):
    #Customer arrives, is served and leaves.
    arrive = env.now
    print('%7.4f %s: Here I am' % (arrive, name))

    with ResRooms.request() as req:
        results = yield req | env.timeout(MtgLen)

        wait = env.now - arrive

        if req in results:
            # We got to the ResRooms
            print('%7.4f %s: Waited %6.3f' % (env.now, name, wait))

            #tib = random.expovariate(1.0 / TimeInMtg)
            yield env.timeout(TimeInMtg)
            print('%7.4f %s: Finished' % (env.now, name))

        else:
            # We reneged
            #req.cancel() this doesnt clear queue and does give an error at last step
            # no notable effect  ResRooms.release(req)
            #simpy.Interrupt('No rooms')  still piling up. no effect
            #yield env.timeout(TimeInMtg)
            print('%7.4f %s: RENEGED after %6.3f' % (env.now, name, wait))
        print("this req=",req)  # is something like   <Request() object at 0x2449892f908>
        print("users",ResRooms.users)
        print("queue",ResRooms.queue)

env = simpy.Environment()

# Start processes and run
ResRooms = simpy.Resource(env, capacity=3)
MtgLen = 1
Hours = 8


env.process(Schedule(env, NbrMtgs, INTERVAL, ResRooms))
env.run(until=5)

Upvotes: 0

Views: 449

Answers (1)

Ana
Ana

Reputation: 51

No that's not an error. If you request the resources the way you did, with the with-statement, all the request that did not get the resource will end up in the queue and wait until the resource is available again. Do you want to cancel those requests?

Upvotes: 1

Related Questions