“select” on multiple Python multiprocessing Queues?

前端 未结 8 1486
情书的邮戳
情书的邮戳 2020-12-24 01:55

What\'s the best way to wait (without spinning) until something is available in either one of two (multiprocessing) Queues, where both reside on the same system?

相关标签:
8条回答
  • 2020-12-24 02:38

    You could use something like the Observer pattern, wherein Queue subscribers are notified of state changes.

    In this case, you could have your worker thread designated as a listener on each queue, and whenever it receives a ready signal, it can work on the new item, otherwise sleep.

    0 讨论(0)
  • 2020-12-24 02:43

    As of Python 3.3 you can use multiprocessing.connection.wait to wait on multiple Queue._reader objects at once.

    0 讨论(0)
提交回复
热议问题