make sure iteration stops

The for ev in queue iteration will block when the queue is empty, and will just wait for
the next request to put something in the queue, and never finish the while loop.
So put a StopIteration exception in the queue before iteration so that it continues to run
the endless while loop.