Drain or discard a generator without looping?

后端 未结 3 894
栀梦
栀梦 2021-01-14 13:58

In an exception handler for a CSP style process, I need to read and discard the entire contents of a channel in order to allow other processes that are blocking to send to i

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 14:28

    I've started using a deque that I can reuse if need be:

    do_all = deque(maxlen=0).extend
    

    Then I can consume generator expressions using:

    do_all(poly.draw() for poly in model.polys)
    

提交回复
热议问题