Say that I have a context manager, CM, that creates a new API session. How can I create a new context manager every 10 iterations of using it? The issue is that the API can only handle so many requests.
counter = 0
# <some loop make new session when counter reaches 10>
with new_session() as session:
# Do stuff
counter += 1
My first thought was to do something like if counter % 10 == 0: make new session
but that doesn’t preserve the session for the whole 10 iterations.
I can’t figure out how to set up the loop.