简体   繁体   中英

Release resource being held by another process

In SimPy, if I've process a , b and resource r and do:

yield request, self, r #request done in process a

How can I release the resource from process b?

yield release, a, r #release done in b (being a an instance of class a), doesn't work

I've also tried:

r.activeQ.remove(a)

And it actually removes from the active queue, however it won't do all the implicit steps made when doing a yield and it turns out to be kind of pointless.

Can it be done? if yes, how?

Well, my problem was process b was actually inactive and therefore any yield call would be unsuccessful.

A workaround I came up with was

activate(a, a.function()) #called from process b

Where

class a(Process):
    def function(self):
        yield release, self, r
        yield passivate, self

Hope this can help anyone out there having the same problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM