iterator interface for Queue?

Paul Rubin http
Sun Apr 8 02:40:37 EDT 2007


Is there any reason Queue shouldn't have an iterator interface?
I.e. instead of

    while True:
       item = work_queue.get()
       if item is quit_sentinel:
           # put sentinel back so other readers can find it
           work_queue.put(quit_sentinel)  
           break
       process(item)

with accompanying hair on the other side to create and send a sentinel,
you'd just say:

     for item in work_queue:
        process(item)

You'd still need hair at the writing end to tell the readers when to
finish, either by directly inserting a sentinel or with 
"work_queue.done()" or something like that.



More information about the Python-list mailing list