两个python脚本之间的通信 [英] Communication between two python scripts

查看:908
本文介绍了两个python脚本之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法论问题:

我有一个主" python脚本,该脚本在系统上无限循环运行,并且我想偶尔向其发送信息(例如json数据字符串)以及其他一些python脚本,这些脚本稍后由我自己启动或其他程序,并且将在发送字符串后立即结束.

I have a "main" python script which runs on an infinite loop on my system, and I want to send information to it (a json data string for example) occasionally with some other python scripts that will be started later by myself or another program and will end just after sending the string.

我在这里不能使用子进程,因为我的主脚本不知道其他脚本何时运行以及它们将执行什么代码.

I can't use subprocess here because my main script doesn't know when the other will run and what code they will execute.

我正在考虑使主脚本在本地端口上侦听,并使其他脚本在该端口上向它发送字符串,但是有更好的方法吗?

I'm thinking of making the main script listen on a local port and making the other scripts send it the strings on that port, but is there a better way to do it ?

推荐答案

zeromq: http://www.zeromq.org/-是进程间通信的最佳解决方案,恕我直言,并且对python具有出色的绑定: http://www.zeromq.org/bindings:python

zeromq: http://www.zeromq.org/ - is best solution for interprocess communications imho and have a excelent binding for python: http://www.zeromq.org/bindings:python

这篇关于两个python脚本之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆