兼容micropython的生产者/订阅者事件总线系统,具有可选线程。
micropython-event-bus的Python项目详细描述
micropython事件总线
带有可选线程的micropython producer/subscriber事件系统
请注意,此包处于早期阶段,因此可能有未记录的错误。
安装
pip3 install micropython-event-bus
或者 将此repository克隆到项目中:
git clone https://github.com/jaycosaur/micropython-event-bus
用法
frommicropython_event_busimportProducer,subscribe# setup simple producermy_producer=Producer(name="my first producer")# create subscriber# with decorator@subscribe(my_producer)defmy_subscriber(*args,**kwargs):print('I got a message!')# or by calling the producer subscribe methoddefmy_second_subscriber(*args,**kwargs):print('I also got a message!')my_producer.subscribe(my_second_subscriber)# emit event# from producer via __call__ methodmy_producer(1,2,3,4)# or by calling emit directlymy_producer.emit(1,2,3,4)
有关更多示例,请参阅examples
贡献
欢迎拉取请求。对于重大变更,请先打开一个问题来讨论您希望更改的内容。