Fix _nextwid so that it handles graceful shutdown properly #634
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.
If you have a watcher with numprocesses=1 and send_hup=false, a reload causes the next wid to be None. Next reload puts it back to 1. Then back to None, etc.
The reason is that the _nextwid property is trying to find an available slot. Since graceful reload starts a new process first, then kills the old, the slots are all full. So _nextwid simply finishes, implicitly returning None.
What is worse, _nextwid would actual raise a RuntimeError if numprocesses > 1 and you try to do a graceful reload.
I rewrote the mechanism to use set unions. I made all_wids be numprocesses * 2 to handle the graceful reload case.