Added threading.Condition object to avoid polling

This follows the original example with slightly different notation to
take advantage of the with statement