Use a collections.deque which has thread safe pop/append