Remove the blocking wait during message routing #413
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR simultaneously improves a failure mode and makes failure more likely. :-)
In more detail:
When a message is sent from a background task to the corresponding future, the following sequence of events occurs:
queue.Queue
instance)Currently, in the main branch, for step 3 we use a blocking
message_queue.get()
operation to get the message. In effect we're assuming that if a message has been put on the queue,message_queue.get()
will not block for long while the message is retrieved. If something goes wrong with some part of the machinery and we somehow get a ping without a corresponding message, then the router will block forever. That's not a great failure mode.With this PR, we use a non-blocking
message_queue.get
operation to get the message. We're now making a stronger assumption than before, namely that we don't need to wait at all for the message that's been put on the queue to arrive. I believe that assumption is justified, though it's difficult to extract a promise of this from the documentation. Now if something goes wrong (a ping arriving without a message being queued), the router will crash with aqueue.Empty
exception. This seems like a better failure mode.While we're touching the
route_until
methods, this PR takes a liberty and cleans up the implementations of those methods slightly. It also adds docstrings for the_route_message
private method.Closes #313 (really, this PR makes #313 invalid, but it resolves the issue that prompted #313).
N.B. The duplication between the
MultithreadingRouter
andMultiprocessingRouter
is still biting us. (cf. #383)