Simpy 3: Resources.Resource.request()/.release() WITHOUT 'with...as:'
python, simpy, simulation
Solution
If you want to use a resource without a `with` block (and you know you won’t get interrupted), its just:
req = resource.request()
yield req
# do stuff
resource.release(req)
Problem
I'm trying to add SimPy simulation to a project I'm working on and I have some confusion about version 3's release/request. I was able to implement resources using a 'with'-block without trouble but in my situation I want to request/release a resource without using a 'with'-block. However, I cannot find an example of this using SimPy 3. I read the documentation/source regarding resources but still can't get it quite right. Could someone explain how to properly: ``` ... Request a Resource with the method: 'request()' ... Release that Resource with the method: 'release()' ... ``` Thanks, and sorry for the bother. PS: I'm intending to use Resources.resource