def _try_put(q, msg, should_terminate_event, timeout=0.001):
        """
        Repeatedly try to put message on queue until success or should_terminate_event is set.
        If success, return False.
        If should_terminate_event is set, return True.
        """
        while not should_terminate_event.is_set():
            try:
                q.put(msg, timeout=timeout)
                return False
            except queue.Full:
                pass
        return True

        Repeatedly try to put message on queue until success or should_terminate_event is set.
        If success, return False.
        If should_terminate_event is set, return True.
        
kosmos-2/infinibatch/infinibatch/iterators.py