异步的lirc python扩展

aiolirc的Python项目详细描述


http://img.shields.io/pypi/v/aiolirc.svghttps://img.shields.io/badge/license-GPLv3-brightgreen.svg

关于

使用python的新工具(async await语法)的异步消息传递,在3.5版中引入是如此有趣!

所以,我决定为 Linux Infra-Red Remote Control(LIRC)

幸运的是,cython在asyncio上运行良好。因此,lirc_clientc扩展是由cython扩展而来的 键入。

此外,还提供了ircspatcher类型和listen_for装饰器。

安装

$ apt-get install liblircclient-dev python3.5-dev build-essential
$ pip install cython
$ pip install aiolirc

快速启动

使用此库的最简单方法是著名的快速启动功能,如下所示:

from aiolirc import very_quickstart, listen_for

@listen_for('play')
async def do_play(loop):
    ...
    # Do play stuff

very_quickstart('my-prog')  # my-prog is configured in your lircrc file.

另一个名为快速启动的协同程序函数也可用。 生命周期:

import asyncio
from aiolirc import quickstart

main_loop = asyncio.get_event_loop()
try:
    main_loop.run_until_complete(quickstart(loop=main_loop))
except KeyboardInterrupt:
    print('CTRL+C detected. terminating...')
    return 1
finally:
    if not main_loop.is_closed():
        main_loop.close()

irc调度器

构造器

def __init__(self, source: LIRCClient, loop: asyncio.BaseEventLoop=None):

用法示例

import asyncio

from aiolirc.lirc_client import LIRCClient
from aiolirc.dispatcher import IRCDispatcher, listen_for

@listen_for('amp power', repeat=5)
async def amp_power(loop):
    ...
    # Do your stuff

@listen_for('amp source')
async def amp_source(loop):
    ...
    # Do your stuff


async with LIRCClient('my-prog') as client:
    dispatcher = IRCDispatcher(client)
    await dispatcher.listen()

lircclient网站

构造函数

def __cinit__(self, lircrc_prog, *, lircrc_file='~/.config/lircrc', loop=None, check_interval=.05, verbose=False,
    blocking=False):

为了进一步控制从lirc接收到的消息,在 调用lircclient.lirc_init()。并确保在完成工作后调用了lircclient.lirc_deinit()。 使用lircclient

from aiolirc.lirc_client import LIRCClient

client = LIRCClient('my-prog')
try:
    client.lirc_init()
    async for cmd in client:
        print(cmd)
finally:
    client.lirc_deinit()

您可以使用lircclient作为异步上下文管理器,如下所述,以自动调用 lircclient.lirc_init()lircclient.lirc_deinit()函数,并获取一个锁以防止 从lirc_client wrapper读取消息中的lircclient实例:

from aiolirc.lirc_client import LIRCClient

async with LIRCClient('my-prog') as client:
    async for cmd in client:
        print(cmd)

系统d

创建main.py:

import sys
import asyncio

from aiolirc import IRCDispatcher, LIRCClient

async def launch(self) -> int:

    async with LIRCClient('my-prog', lircrc_file='path/to/lircrc', check_interval=.06) as client:
        dispatcher = IRCDispatcher(client)
        result = (await asyncio.gather(dispatcher.listen(), return_exceptions=True))[0]

    if isinstance(result, Exception):
        raise result

    return 0

def main(self):

    main_loop = asyncio.get_event_loop()
    try:
        return main_loop.run_until_complete(launch())
    except KeyboardInterrupt:
        print('CTRL+C detected.')
        return 1
    finally:
        if not main_loop.is_closed():
            main_loop.close()

if __name__ == '__main__':
    sys.exit(main())

/etc/systemd/system/aiolirc.service文件:

[Unit]
Description=aiolirc

[Service]
ExecStart=python3.5 /path/to/main.py
User=user
Group=group

[Install]
WantedBy=multi-user.target

系统控制:

$ systemctl enable aiolirc
$ systemctl start aiolirc
$ systemctl restart aiolirc

$ ps -Af | grep 'main.py'

$ systemctl stop aiolirc

更改日志

0.1.0

  • README.rst

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
雅加达。木卫一。WriteAbortedException:写入中止;JAVA木卫一。NotSerializableException   如果没有互联网连接,java“重启”应用程序   ant将我的Mac更新为最新的Java JDK时遇到的困难   java从边的文本文件创建网络   java多个枚举与一个枚举   使用XML进行JavaBean验证:字段上的多个相同约束   java Eclipse报告HTML警告以获得正确的(正如我假设的)代码   java使用Jackson从POJO数组生成JSON模式   在JTextPane java swing中填充行的rectange后无法与视图同步   如何编写Java字符串。格式化为ruby代码?   java如何使Hibernate标准只包含所需字段   在java中拆分字符串,更改字母和分组   mysql Java 1.8.0_60,MariaDB v10。0和mariadbjavaclient 1.2.2,“未找到合适的驱动程序”   java试图做一个简单的计算,结果不正确   javatomcat远程访问   java我安装了安卓 studio,创建了我的第一个项目,面对这个错误。。。我点击了所有链接,但什么都没发生   JavaSpring3。0注释   SwingJavaJLabel。setText()方法重载时不使用字符串