Simpy how to access objects in a resource queue
<p>I am moving code written in Simpy 2 to version 3 and could not find an equivalent to the following operation.</p>

<p>In the code below I access job objects (derived from class job_(Process)) in a Simpy resource's activeQ.</p>

<pre><code>def select_LPT(self, mc_no):
    job = 0
    ptime = 0
    for j in buffer[mc_no].activeQ:
        if j.proc_time[mc_no] &gt; ptime:
            ptime = j.proc_time[mc_no]
            job = j

    return job
</code></pre>

<p>To do this in Simpy 3, I tried the following </p>

<p><code>buffers[mc_no].users</code></p>

<p>which returns a list of Request() objects. With these objects I cannot access the processes that created them, nor the objects these process functions belong to. (using the 'put_queue', and 'get_queue' of the Resource object did not help)</p>

<p>Any suggestions ?</p>

<p>In SimPy, request objects do not know which process created them.  However, since we are in Python land you can easily add this information:</p>

<pre><code>with resource.request() as req:
    req.obj = self
    yield req
    ...

 # In another process/function
 for user_req in resource.users:
     print(user_req.obj)
</code></pre>

python simulation simpy