python的进程间通信 [英] Inter-process communication for python

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

问题描述

我在为我的 Python 应用程序创建进程间通信时遇到问题.我手头有两个python脚本,假设A和B.A用于打开一个巨大的文件,将其保存在内存中并进行一些Mysql无法完成的处理,而B是一个经常用于查询A的进程.

I'm having a problem creating a inter-process communication for my python application. I have two python scripts at hand, let's say A and B. A is used to open a huge file, keep it in memory and do some processing that Mysql can't do, and B is a process used to query A very often.

由于A需要读取的文件真的很大,我希望读取一次就挂在那里等待我的Bs查询.

Since the file A needs to read is really large, I hope to read it once and have it hang there waiting for my Bs' to query.

我现在要做的是,我使用cherrypy来构建一个http服务器.但是,我觉得这样做有点尴尬,因为我正在尝试做的绝对是本地的.所以,我想知道还有其他更自然的方式来实现这个目标吗?

What I do now is, I use cherrypy to build a http-server. However, I feel it's kind of awkward to do so since what I'm trying to do is absolutely local. So, I'm wondering are there other more organic way to achieve this goal?

我不太了解 TCP/socket 等.如果可能的话,玩具示例将不胜感激(请包括读取文件的部分).

I don't know much about TCP/socket etc. If possible, toy examples would be appreciate (please include the part to read file).

推荐答案

Python 对 ZeroMQ 有很好的支持,这比使用原始套接字更容易和更健壮.

Python has good support for ZeroMQ, which is much easier and more robust than using raw sockets.

ZeroMQ 站点将 Python 视为其主要语言之一,并在其文档中提供了大量 Python 示例.确实,学习基础知识"中的示例是用 Python 编写的.

The ZeroMQ site treats Python as one of its primary languages and offers copious Python examples in its documentation. Indeed, the example in "Learn the Basics" is written in Python.

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

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