From 1c3d22fcf5305ebe506c4ac1e5ab760b7ddf4c04 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Wed, 18 Feb 2015 08:56:52 -0500 Subject: [PATCH] Fix multiple calls to Event.clear. --- tornado/locks.py | 3 ++- tornado/test/locks_test.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tornado/locks.py b/tornado/locks.py index 62d962b815..73cc9e2b8b 100644 --- a/tornado/locks.py +++ b/tornado/locks.py @@ -110,7 +110,8 @@ def clear(self): Calls to `.wait` will block until `.set` is called. """ - self._future = Future() + if self._future.done(): + self._future = Future() def wait(self, timeout=None): """Block until the internal flag is true. diff --git a/tornado/test/locks_test.py b/tornado/test/locks_test.py index 49e6199cce..73f0f5911f 100644 --- a/tornado/test/locks_test.py +++ b/tornado/test/locks_test.py @@ -206,6 +206,15 @@ def test_event_set_multiple(self): e.set() self.assertTrue(e.is_set()) + def test_event_wait_clear(self): + e = locks.Event() + f0 = e.wait() + e.clear() + f1 = e.wait() + e.set() + self.assertTrue(f0.done()) + self.assertTrue(f1.done()) + if __name__ == '__main__': unittest.main()