This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author davin
Recipients Alexei.Mozhaev, davin, sbt, torsten
Date 2015-03-05.17:49:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1425577763.53.0.674919111972.issue20147@psf.upfronthosting.co.za>
In-reply-to
Content
This same issue came up recently in issue23582.  Really, it should have been addressed in this issue here first and issue23582 marked as a duplicate of this one but these things don't always happen in a synchronous or apparently-linear fashion.

Adding to what is captured in issue23582, specifically referring to the points raised here in this issue:
1. A call to put does not mean that the data put on the queue is instantly/atomically available for retrieval via get.  Situations where a call to put is immediately followed by a non-blocking call to get are asking for a race-condition -- this is a principal reason for having blocking calls with timeouts.
2. A call to get resulting in an Empty exception of course does not mean that the queue is forevermore empty, only that the queue is empty at the moment the call to get was made -- the facility for trapping the Empty and trying again to get more data off the queue provides welcome flexibility on top of the use of blocking/non-blocking calls with/without timeouts.
3. A call to empty is, as indicated in the documentation, not to be considered reliable because of the semantics in coordinating the queue's state and data between processes/threads.
4. Alexei's contributions to this issue are very nearly identical to what is discussed in issue23582 and are addressed well there.
5. As to using a timeout value too small to be effective (i.e. < 2e-6), really this is one example of the larger concern of choosing an appropriate timeout value.  In the proposed patch, ensuring that a call to self._poll is made no matter what might potentially buy additional time for the data to be synced and made available (admittedly a happy result, but a fragile, inadvertent win) but it does not address the rest of how get, put, and the others work nor will it necessarily solve the issue being raised here.

In Alexei's example, changing the call to get from a non-blocking call to a blocking call with a reasonably small timeout will reliably ensure that everything put on the queue can and will be gotten back by the rest of that code.

In multiprocessing, we have queues to help us make data available to and across processes and threads alike -- we must recognize that coordinating data across distinct processes (especially) takes a non-zero amount of time -- hence we have the tools of blocking as well as non-blocking calls both with or without timeouts to properly implement robust code in these situations.
History
Date User Action Args
2015-03-05 17:49:23davinsetrecipients: + davin, torsten, sbt, Alexei.Mozhaev
2015-03-05 17:49:23davinsetmessageid: <1425577763.53.0.674919111972.issue20147@psf.upfronthosting.co.za>
2015-03-05 17:49:23davinlinkissue20147 messages
2015-03-05 17:49:22davincreate