Rev 5250: join(timeout=0) is useful to check for an exception without stopping the thread. in file:///home/vila/src/bzr/experimental/leaking-tests/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed May 26 12:05:29 BST 2010
At file:///home/vila/src/bzr/experimental/leaking-tests/
------------------------------------------------------------
revno: 5250
revision-id: v.ladeuil+lp at free.fr-20100526110529-865s1k26bdj4s9md
parent: v.ladeuil+lp at free.fr-20100526104407-0w315whpmsdeafjk
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: propagate-exceptions
timestamp: Wed 2010-05-26 13:05:29 +0200
message:
join(timeout=0) is useful to check for an exception without stopping the thread.
* bzrlib/tests/test_server.py:
(ThreadWithException.join): Document the timeout=0 idiom.
* bzrlib/tests/test_transport.py:
(TestThreadWithException.test_exception_is_re_raised): Ensure
join(timeout=0) can be called while leaving the thread running
-------------- next part --------------
=== modified file 'bzrlib/tests/test_server.py'
--- a/bzrlib/tests/test_server.py 2010-05-26 10:44:07 +0000
+++ b/bzrlib/tests/test_server.py 2010-05-26 11:05:29 +0000
@@ -248,7 +248,12 @@
self.exception = sys.exc_info()
def join(self, *args, **kwargs):
- """Overrides Thread.join to raise any exception caught."""
+ """Overrides Thread.join to raise any exception caught.
+
+
+ Calling join(timeout=0) will raise the caught exception or return None
+ is the thread is still alive.
+ """
# Note that we don't care about the timeout parameter here: either the
# thread has raised an exception and it should be raised (and join()
# should succeed whatever the timeout is) or it's still alive which
=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py 2010-05-26 10:44:07 +0000
+++ b/bzrlib/tests/test_transport.py 2010-05-26 11:05:29 +0000
@@ -1011,3 +1011,21 @@
tt = test_server.ThreadWithException(target=raise_my_exception)
tt.start()
self.assertRaises(MyException, tt.join)
+
+ def test_join_when_no_exception(self):
+ resume = threading.Event()
+ class MyException(Exception):
+ pass
+
+ def raise_my_exception():
+ # Wait for the test to tell us to resume
+ resume.wait()
+ # Now we can raise
+ raise MyException()
+
+ tt = test_server.ThreadWithException(target=raise_my_exception)
+ tt.start()
+ tt.join(timeout=0)
+ self.assertIs(None, tt.exception)
+ resume.set()
+ self.assertRaises(MyException, tt.join)
More information about the bazaar-commits
mailing list