Add close method to queue
I have a problem with notifying all current subscribers and new subscribers about the closure of the queue and the reason. For example, I have a producer that reads messages from websocket or something else and send this to a queue, and several consumers (I do not know how many). If any exception occurred, then all current subscribers and subscribers which will be added later should know about this error. I tried to send an exception to a queue, but that did not help, because I have several consumers. Also, this will not protect new consumers. I propose to add a new close method with exc argument, which will throw an exception when calling the get method, and also throw an exception for all current _getters.
On 9 Jun 2020, at 13:20, Kazantcev Andrey <heckad@yandex.ru> wrote:
I have a problem with notifying all current subscribers and new subscribers about the closure of the queue and the reason. For example, I have a producer that reads messages from websocket or something else and send this to a queue, and several consumers (I do not know how many). If any exception occurred, then all current subscribers and subscribers which will be added later should know about this error. I tried to send an exception to a queue, but that did not help, because I have several consumers. Also, this will not protect new consumers. I propose to add a new close method with exc argument, which will throw an exception when calling the get method, and also throw an exception for all current _getters.
What I do when I want to send a program-state-change to consumers is to put N copies of the state-change object into the queue, one for each consumer. Then the consumers get the state-change object and do what it instructs. Of course that requires that I know how many consumers there are. I am wondering why you use-case means you do not know the number of consumers. In the simplest case I put copies of None on the queue to signal quit. For a parallel build tool I put build-state objects into the queue and quit when all build threads have finished, which is when the build-state's is_finished is True. When build-state is_finished is False I just log progress messages. Barry
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/EYVGOE... Code of Conduct: http://python.org/psf/codeofconduct/
participants (2)
-
Barry Scott
-
Kazantcev Andrey