Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #2572

decorator 4.1 is out

From Michele Simionato <michele.simionato@gmail.com>
Newsgroups comp.lang.python.announce
Subject decorator 4.1 is out
Date 2017-07-15 06:33 -0700
Message-ID <mailman.115.1500294005.29743.python-announce-list@python.org> (permalink)
References <4ac8d3f7-493b-4d90-b63f-98b27d2dc37c@googlegroups.com>

Show all headers | View raw


Dear all,

a new release of the decorator module is out. For the first time we support decorating Python 3.5 coroutines. For instance, this is an example of how to implement a tracing decorator called log_start_stop that you can use for debugging:

import time
import logging
from asyncio import get_event_loop, sleep, wait
from decorator import decorator

@decorator
async def log_start_stop(coro, *args, **kwargs):
    logging.info('Starting %s%s', coro.__name__, args)
    t0 = time.time()
    await coro(*args, **kwargs)
    dt = time.time() - t0
    logging.info('Ending %s%s after %d seconds', coro.__name__, args, dt)

@log_start_stop
async def make_task(n):
    for i in range(n):
        await sleep(1)

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    tasks = [make_task(3), make_task(2), make_task(1)]
    get_event_loop().run_until_complete(wait(tasks))

You will get an output like this:

INFO:root:Starting make_task(1,)
INFO:root:Starting make_task(3,)
INFO:root:Starting make_task(2,)
INFO:root:Ending make_task(1,) after 1 seconds
INFO:root:Ending make_task(2,) after 2 seconds
INFO:root:Ending make_task(3,) after 3 seconds

Also, for the first time the documentation is hosted on readthedocs.org.
Here are the relevant links:

Download: https://pypi.python.org/pypi/decorator/4.1.1
Project: https://github.com/micheles/decorator/
Docs: http://decorator.readthedocs.io/en/latest/index.html

Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread


Thread

decorator 4.1 is out Michele Simionato <michele.simionato@gmail.com> - 2017-07-15 06:33 -0700

csiph-web