Understanding the source code for _trigger_put

34 views
Skip to first unread message

Joe Pedersen

unread,
Nov 27, 2023, 8:08:02 AM11/27/23
to python-simpy
In the documentation for _trigger_put, it states:

The method iterates over all put events in the :attr:`put_queue` and calls :meth:`_do_put` to check if the conditions for the event are met. If :meth:`_do_put` returns ``False``, the iteration is stopped early.

But _do_put can never return False.  It always returns None.

The code for _trigger_put is:

idx = 0 
while idx < len(self.put_queue): 
    put_event = self.put_queue[idx] 
    proceed = self._do_put(put_event) 
    if not put_event.triggered: 
        idx += 1 
    elif self.put_queue.pop(idx) != put_event: 
        raise RuntimeError('Put queue invariant violated') 

    if not proceed: 
        break

Since `proceed` is always `None`, the while loop ALWAYS breaks, so the documentation is incorrect, the method DOES NOT iterate over all put events in the :attr:`put_queue`

Is there something that I'm wrong about? or missing?

Best regards,
Joe
Reply all
Reply to author
Forward
0 new messages