一个小型的点对点数据流库

simplestreamer的Python项目详细描述


#简单团队

这是一个小型(<;150 loc)对等数据流库,专为高频状态数据设计。 它使用pickle底层来序列化数据,因此您可以通过它转储任何python对象。

你可以用 pip install simplestreamer

下面是一个如何使用它的快速示例。希望这足够不言自明了。

节点1代码:

# just dumps time data into the streamer at 100 hz
import simplestreamer
import time

streamer = simplestreamer.SimpleStreamer(5200)

while True:
    streamer.send_data({"current time.time()": time.time()})
    time.sleep(0.01)

节点2(以及3、4等)代码:

# subscribes to the stream from node 1 and periodically reads the data
import simplestreamer
import time

streamer = simplestreamer.SimpleStreamer(5201)
streamer.subscribe("127.0.0.1", 5200, "streamer 1")
# You can optionally configure the rate at which the remote streamer sends you data
#streamer.subscribe("127.0.0.1", 5200, "streamer 1", updates_per_sec=1.5)

while True:
    print(streamer.get_data("streamer 1"))
    time.sleep(0.5)

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

推荐PyPI第三方库


热门话题
AmazonS3查找从S3forJava下载的压缩文件的MIME类型   java如何使用Selenium在<span>中查找具有特定文本的元素   python如何使用OpenIEDemo生成自定义三元组。由stanfordnlp提供的java   java遇到“方法不适用”编译错误   java如何使用Mockito在Looper中运行的验证代码。getMainLooper?   类Java目录错误   java在已知其他泛型信息时使用原始类型   java connect()和disconnect()在哪里实现?   java使用PDF Box库拆分PDF,生成的PDF几乎与源PDF文件大小相同   java PowerMockito返回错误的对象   java如何找到TIBCO集合消息的字节编码?   java Basic音乐播放器下一步和上一步按钮   添加模块描述符时,java没有名为“entityManagerFactory”的bean可用   java为什么我的代码不是线程安全的?   eclipse java。引用项目中的类的lang.NoClassDefFoundError