1

I am moving code written in Simpy 2 to version 3 and could not find an equivalent to the following operation.

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

def select_LPT(self, mc_no):
    job = 0
    ptime = 0
    for j in buffer[mc_no].activeQ:
        if j.proc_time[mc_no] > ptime:
            ptime = j.proc_time[mc_no]
            job = j

    return job

To do this in Simpy 3, I tried the following

buffers[mc_no].users

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)

Any suggestions ?

1 Answers1

2

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

with resource.request() as req:
    req.obj = self
    yield req
    ...

 # In another process/function
 for user_req in resource.users:
     print(user_req.obj)
Stefan Scherfke
  • 3,012
  • 1
  • 19
  • 28
  • Long live the land of Python ! - Thank you. I have a follow up question: I have a job class that has a process function go() - as in Simpy 2. With req.obj = self I stick the object data, now how to I stick the process data. I need it because I want to interrupt the process and have the job object resume its flow. – Suleyman Karabuk Aug 31 '16 at 18:04
  • 1
    Never mind - figured it out. Just create the process in the constructor of the object, keep it as an attribute, then access through the job object. – Suleyman Karabuk Sep 02 '16 at 15:32
  • uh ah, do you have an example for that? @Suleyman Karabuk – veritaS Jul 11 '23 at 08:31