From af963e6fbe7771f6abf038091e1b558e592d12e2 Mon Sep 17 00:00:00 2001 From: Tobias Oberstein Date: Thu, 9 Feb 2017 14:47:24 +0100 Subject: [PATCH 1/3] add sleep helper; some cosmetics --- README.rst | 7 ++----- txaio/__init__.py | 42 ++++++++++++++++++++++-------------------- txaio/_unframework.py | 2 ++ txaio/_version.py | 2 +- txaio/aio.py | 12 ++++++++++++ txaio/tx.py | 20 ++++++++++++++++++++ 6 files changed, 59 insertions(+), 26 deletions(-) diff --git a/README.rst b/README.rst index d1c1296..cfbb9a8 100644 --- a/README.rst +++ b/README.rst @@ -65,14 +65,11 @@ Please refer to the `documentation `_ f .. |Version| image:: https://img.shields.io/pypi/v/txaio.svg :target: https://pypi.python.org/pypi/txaio -.. |Master Branch| image:: https://img.shields.io/badge/branch-master-orange.svg - :target: https://travis-ci.org/crossbario/txaio.svg?branch=master - .. |Build Status| image:: https://travis-ci.org/crossbario/txaio.svg?branch=master :target: https://travis-ci.org/crossbario/txaio -.. |Coverage| image:: https://img.shields.io/codecov/c/github/crossbario/txaio/master.svg +.. |Coverage| image:: https://codecov.io/github/crossbario/txaio/coverage.svg?branch=master :target: https://codecov.io/github/crossbario/txaio -.. |Docs| image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat +.. |Docs| image:: https://readthedocs.org/projects/txaio/badge/?version=latest :target: https://txaio.readthedocs.io/en/latest/ diff --git a/txaio/__init__.py b/txaio/__init__.py index 931b1c4..29c9555 100644 --- a/txaio/__init__.py +++ b/txaio/__init__.py @@ -65,34 +65,36 @@ __all__ = ( 'config', # the config instance, access via attributes - 'create_future', # create a Future (can be already resolved/errored) + 'create_future', # create a Future (can be already resolved/errored) 'create_future_success', 'create_future_error', - 'create_failure', # return an object implementing IFailedFuture - 'as_future', # call a method, and always return a Future - 'is_future', # True for Deferreds in tx and Futures, @coroutines in asyncio - 'reject', # errback a Future - 'resolve', # callback a Future - 'add_callbacks', # add callback and/or errback - 'gather', # return a Future waiting for several other Futures - 'is_called', # True if the Future has a result + 'create_failure', # return an object implementing IFailedFuture + 'as_future', # call a method, and always return a Future + 'is_future', # True for Deferreds in tx and Futures, @coroutines in asyncio + 'reject', # errback a Future + 'resolve', # callback a Future + 'add_callbacks', # add callback and/or errback + 'gather', # return a Future waiting for several other Futures + 'is_called', # True if the Future has a result - 'call_later', # call the callback after the given delay seconds + 'call_later', # call the callback after the given delay seconds - 'failure_message', # a printable error-message from a IFailedFuture - 'failure_traceback', # returns a traceback instance from an IFailedFuture - 'failure_format_traceback', # a string, the formatted traceback + 'failure_message', # a printable error-message from a IFailedFuture + 'failure_traceback', # returns a traceback instance from an IFailedFuture + 'failure_format_traceback', # a string, the formatted traceback - 'make_batched_timer', # create BatchedTimer/IBatchedTimer instances + 'make_batched_timer', # create BatchedTimer/IBatchedTimer instances - 'make_logger', # creates an object implementing ILogger - 'start_logging', # initializes logging (may grab stdin at this point) - 'set_global_log_level', # Set the global log level - 'get_global_log_level', # Get the global log level + 'make_logger', # creates an object implementing ILogger + 'start_logging', # initializes logging (may grab stdin at this point) + 'set_global_log_level', # Set the global log level + 'get_global_log_level', # Get the global log level 'add_log_categories', - 'IFailedFuture', # describes API for arg to errback()s - 'ILogger', # API for logging + 'IFailedFuture', # describes API for arg to errback()s + 'ILogger', # API for logging + + 'sleep', # little helper for inline sleeping ) diff --git a/txaio/_unframework.py b/txaio/_unframework.py index f967209..8408800 100644 --- a/txaio/_unframework.py +++ b/txaio/_unframework.py @@ -75,3 +75,5 @@ add_log_categories = _throw_usage_error IFailedFuture = _throw_usage_error ILogger = _throw_usage_error + +sleep = _throw_usage_error diff --git a/txaio/_version.py b/txaio/_version.py index 46fb26e..1bf4fdd 100644 --- a/txaio/_version.py +++ b/txaio/_version.py @@ -1 +1 @@ -__version__ = u'2.6.0' +__version__ = u'2.6.1' diff --git a/txaio/aio.py b/txaio/aio.py index ed798af..e020c03 100644 --- a/txaio/aio.py +++ b/txaio/aio.py @@ -424,3 +424,15 @@ def set_global_log_level(level): def get_global_log_level(): return _log_level + + +def sleep(delay, loop=None): + """ + Inline sleep for use in co-routines. + + :param delay: Time to sleep in seconds. + :type delay: float + :param reactor: The asyncio loop to use. + :type reactor: None (to use the default loop) or a loop. + """ + raise Exception('not implemented yet') diff --git a/txaio/tx.py b/txaio/tx.py index 491a950..aa742c2 100644 --- a/txaio/tx.py +++ b/txaio/tx.py @@ -536,3 +536,23 @@ def set_global_log_level(level): def get_global_log_level(): return _log_level + + +def sleep(delay, reactor=None): + """ + Inline sleep for use in co-routines (Twisted ``inlineCallback`` decorated functions). + + .. seealso:: + * `twisted.internet.defer.inlineCallbacks `__ + * `twisted.internet.interfaces.IReactorTime `__ + + :param delay: Time to sleep in seconds. + :type delay: float + :param reactor: The Twisted reactor to use. + :type reactor: None or provider of ``IReactorTime``. + """ + if not reactor: + from twisted.internet import reactor + d = Deferred() + reactor.callLater(delay, d.callback, None) + return d From 741e6a0910639c3e2e1862dec648c30cdb516296 Mon Sep 17 00:00:00 2001 From: Tobias Oberstein Date: Thu, 9 Feb 2017 15:00:57 +0100 Subject: [PATCH 2/3] make flake happy --- txaio/__init__.py | 2 +- txaio/tx.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/txaio/__init__.py b/txaio/__init__.py index 29c9555..f3c7ea7 100644 --- a/txaio/__init__.py +++ b/txaio/__init__.py @@ -81,7 +81,7 @@ __all__ = ( 'failure_message', # a printable error-message from a IFailedFuture 'failure_traceback', # returns a traceback instance from an IFailedFuture - 'failure_format_traceback', # a string, the formatted traceback + 'failure_format_traceback', # a string, the formatted traceback 'make_batched_timer', # create BatchedTimer/IBatchedTimer instances diff --git a/txaio/tx.py b/txaio/tx.py index aa742c2..8a95522 100644 --- a/txaio/tx.py +++ b/txaio/tx.py @@ -540,11 +540,7 @@ def get_global_log_level(): def sleep(delay, reactor=None): """ - Inline sleep for use in co-routines (Twisted ``inlineCallback`` decorated functions). - - .. seealso:: - * `twisted.internet.defer.inlineCallbacks `__ - * `twisted.internet.interfaces.IReactorTime `__ + Inline sleep for use in co-routines. :param delay: Time to sleep in seconds. :type delay: float From a51d7cd91c8cdd5957c3703fa37d88334c50257e Mon Sep 17 00:00:00 2001 From: Tobias Oberstein Date: Thu, 9 Feb 2017 15:16:58 +0100 Subject: [PATCH 3/3] update release docs --- docs/releases.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/releases.rst b/docs/releases.rst index 2c7d49d..d757721 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -1,9 +1,17 @@ txio releases ============= +2.6.1 +----- + +- February 9, 2017 +- added inline sleep helper (Twisted only for now) + + 2.6.0 ----- +- December 29, 2016 - avoid giving negative times to `callLater` with batched timers (issue #81)