Not able to cancel run in stream loop when status is not in_progress

I am running for loop (for event in stream: ) and when i want to cancel run, it is not cancelled in between this loop. How can I solve this.