From d26183452f1e00fac38ad28d3817803605f884d6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 22 Nov 2014 01:47:08 +0100 Subject: link_future() only accepts coroutine objects, not coroutine functions --- aiogreen.py | 2 +- doc/using.rst | 2 +- tests/test_eventlet.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/aiogreen.py b/aiogreen.py index f1ec37c..45b4ac4 100644 --- a/aiogreen.py +++ b/aiogreen.py @@ -301,7 +301,7 @@ def wrap_greenthread(gt, loop=None): def link_future(future, loop=None): - """Wait for a future, a task, or a coroutine from a greenthread. + """Wait for a future, a task, or a coroutine object from a greenthread. Return the result or raise the exception of the future. diff --git a/doc/using.rst b/doc/using.rst index 5fcf043..0956085 100644 --- a/doc/using.rst +++ b/doc/using.rst @@ -115,7 +115,7 @@ link_future .. function:: link_future(future, loop=None) - Wait for a future, a task, or a coroutine from a greenthread. + Wait for a future, a task, or a coroutine object from a greenthread. Return the result or raise the exception of the future. diff --git a/tests/test_eventlet.py b/tests/test_eventlet.py index 2361e81..4a8970c 100644 --- a/tests/test_eventlet.py +++ b/tests/test_eventlet.py @@ -234,6 +234,23 @@ class LinkFutureTests(tests.TestCase): self.loop.run_forever() self.assertEqual(result, ['error']) + def test_link_future_invalid_type(self): + def func(obj): + return aiogreen.link_future(obj) + + @asyncio.coroutine + def coro_func(): + print("do something") + + def regular_func(): + return 3 + + for obj in (coro_func, regular_func): + gt = eventlet.spawn(func, coro_func) + # ignore logged traceback + with tests.mock.patch('traceback.print_exception') as m_print: + self.assertRaises(TypeError, gt.wait) + def test_link_future_wrong_loop(self): result = [] loop2 = asyncio.new_event_loop() -- cgit v1.2.1