Search code examples
pythonsimpy

Can I get 'until' parameter value at runtime?


I have been wondering whether it is possible to extract value of 'until' parameter passed to simpy.run() method at runtime. It is probably possible to around this issue by storing this value elsewhere, but it may be I am just curious if simpy provides such feature (in the end env has to be aware when to stop running).

I tried to print the result of: dir(env), but I have not found anything interesting there.

enter image description here


Solution

  • You can find the implementation for Environment.run() here.

    It looks like the until argument is converted into an Event with a "stop simulation" callback that is schedule()d.

    If you really need the until time, you could walk Environment._queue, looking for something with an Event whose callback is StopSimulation.callback, but that's hardly straightforward.

    You'll likely be best off just storing the "next" until time somewhere else.

    If needed, maybe directly on the instance...

    env._next_until = 123  # Hack: stash the next until time
    env.run(until=env._next_until)