From reading the docs and questions/answers here, there is no "fair" semaphore in Python, which means that under stress conditions, it becomes likely that some threads will starve.
In this thread (fair-semaphore-in-python), the answer suggests to use a queue of events, where each time, the thread that ends its work will signal to the next thread that it's safe to start. The problem with it is that the last thread will wait forever to signal to the next thread, which does not exist and will thus never come.
My question is, whether there is a way to implement a fair semaphore in Python? Are the threading.queue objects fair? (since if so, then it should be possible to reimplement the acquire() method to wait until it reaches the end of the queue and thus enforce fairness)
threading.queueobjects fair?" That's not optional behavior for queues. If something is called a "queue", then that means, by definition, that objects come out in the same order that they went in.q.put(a), and then another thread subsequently is blocked inq.put(b), you want a guarantee that theaalways will go in to the queue before thebgoes in. Is that right?