fix issue #879 and add a test for it

Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
Use a condition variable instead of sleeping
Documented fix for #879