Function Reference¶
greenado.concurrent¶
-
exception
greenado.concurrent.TimeoutError[source]¶ Bases:
ExceptionException raised by
gyieldin timeout.
-
greenado.concurrent.gcall(f, *args, **kwargs)[source]¶ Calls a function, makes it asynchronous, and returns the result of the function as a
tornado.concurrent.Future. The wrapped function may usegyield()to pseudo-synchronously wait for a future to resolve.This is the same code that
@greenado.groutineuses to wrap functions.Parameters: - f – Function to call
- args – Function arguments
- kwargs – Function keyword arguments
Returns: Warning
You should not discard the returned Future or exceptions may be silently discarded, similar to a tornado coroutine. See
@gen.coroutinefor details.
-
greenado.concurrent.generator(f)[source]¶ A decorator that allows you to use the ‘yield’ keyword in a function, without requiring callers to also yield this function.
The yield keyword can be used inside a decorated function on any function call that returns a future object, such as functions decorated by
@gen.coroutine, and most of the tornado API as of tornado 4.0.Similar to
@gen.coroutine, in versions of Python before 3.3 you must raisetornado.gen.Returnto return a value from this function.This function must only be used by functions that either have a
@greenado.groutinedecorator, or functions that are children of functions that have the decorator applied.New in version 0.1.7.
Warning
You should not discard the returned Future or exceptions may be silently discarded, similar to a tornado coroutine. See
@gen.coroutinefor details.
-
greenado.concurrent.gmoment()[source]¶ Similar to
tornado.gen.moment(), yields the IOLoop for a single iteration from inside a groutine.
-
greenado.concurrent.groutine(f)[source]¶ A decorator that makes a function asynchronous and returns the result of the function as a
tornado.concurrent.Future. The wrapped function may usegyield()to pseudo-synchronously wait for a future to resolve.The primary advantage to using this decorator is that it allows all called functions and their children to use
gyield(), and doesn’t require the use of generators.If you are calling a groutine-wrapped function from a function with a
@greenado.groutinedecorator, you will need to usegyield()to wait for the returned future to resolve.From a caller’s perspective, this decorator is functionally equivalent to the
@gen.coroutinedecorator. You should not use this decorator and the@gen.coroutinedecorator on the same function.Warning
You should not discard the returned Future or exceptions may be silently discarded, similar to a tornado coroutine. See
@gen.coroutinefor details.
-
greenado.concurrent.gsleep(timeout)[source]¶ This will yield and allow other operations to occur in the background before returning.
Parameters: timeout – Number of seconds to wait New in version 0.1.9.
-
greenado.concurrent.gyield(future, timeout=None)[source]¶ This is functionally equivalent to the ‘yield’ statements used in a
@gen.coroutine, but doesn’t require turning all your functions into generators – so you can use the return statement normally, and exceptions won’t be accidentally discarded.This can be used on any function that returns a future object, such as functions decorated by
@gen.coroutine, and most of the tornado API as of tornado 4.0.This function must only be used by functions that either have a
@greenado.groutinedecorator, or functions that are children of functions that have the decorator applied.Parameters: - future – A
tornado.concurrent.Futureobject - timeout – Number of seconds to wait before raising a
TimeoutError. Default is no timeout. Parameter added in version 0.1.8.
Returns: The result set on the future object
Raises: - If an exception is set on the future, the exception will be thrown to the caller of gyield.
- If the timeout expires,
TimeoutErrorwill be raised.
Changed in version 0.1.8: Added timeout parameter
Changed in version 0.2.0: If a timeout occurs, the
TimeoutErrorwill not be set on the future object, but will only be raised to the caller.- future – A
greenado.testing¶
-
greenado.testing.gen_test(func=None, timeout=None)[source]¶ An implementation of
tornado.testing.gen_test()for@greenado.groutineExample:
def something_that_yields(): greenado.gyield(something()) class MyTest(AsyncTestCase): @greenado.testing.gen_test def test_something(self): something_that_yields()