semvec/pypi-packages huggingface dataset:
async_armor 0.0.2
Graceful drop-in replacement for asyncio.shield
Keywords: asyncio

async_armor
===========

:info: Graceful drop-in replacement for asyncio.shield

.. image:: https://img.shields.io/travis/wikibusiness/async_armor.svg
    :target: https://travis-ci.org/wikibusiness/async_armor

.. image:: https://img.shields.io/pypi/v/async_armor.svg
    :target: https://pypi.python.org/pypi/async_armor

Installation
------------

.. code-block:: shell

    pip install async_armor

Usage
-----

.. code-block:: python

    import asyncio

    from async_armor import armor

    calls = 0

    async def call_shield():
        global calls
        await asyncio.sleep(1)
        calls += 1

    @armor
    async def call_deco():
        global calls
        await asyncio.sleep(1)
        calls += 1

    async def main():
        task = armor(call_shield())
        task.cancel()

        task = asyncio.ensure_future(call_deco())
        task.cancel()

    loop = asyncio.get_event_loop()

    loop.run_until_complete(main())

    armor.close()
    loop.run_until_complete(armor.wait_closed())

    assert calls == 2

    loop.close()


Python 3.3+ is required
aiompd 0.4.0
MPD (Music Player Daemon) client for asyncio
Keywords: mpd

============================================
MPD (Music Player Daemon) client for asyncio
============================================

Usage example:

.. code:: python

    import asyncio
    import aiompd

    URLS = [
        "http://mega5.fast-serv.com:8134",
        "http://176.31.240.114:8326",
        "http://74.86.186.4:10042",
        "http://s14.myradiostream.com:4668",
    ]
    PLAY_TIME = 10


    @asyncio.coroutine
    def nexter(mpc):
        yield from mpc.clear()

        for url in URLS:
            yield from mpc.add(url)

        for n in range(len(URLS)):
            yield from mpc.play(track=n)
            yield from asyncio.sleep(PLAY_TIME)


    @asyncio.coroutine
    def volumer(mpc):
        timeout = (len(URLS) * PLAY_TIME) / 200

        for volume in range(0, 101, 1):
            yield from mpc.set_volume(volume)
            yield from asyncio.sleep(timeout)

        for volume in range(100, -1, -1):
            yield from mpc.set_volume(volume)
            yield from asyncio.sleep(timeout)


    def main():
        loop = asyncio.get_event_loop()
        mpc = loop.run_until_complete(aiompd.Client.make_connection())
        loop.run_until_complete(asyncio.wait([nexter(mpc), volumer(mpc)]))


    if __name__ == '__main__':
        main()