def readframes(cv):
    while True:
        success, frame = cv.read()
if success:
    yield frame
else:
    return
How to use return value of a function as condition of while that returns tuple in python