简体   繁体   English

在Python中接收API调用

[英]Receiving API calls in Python

I am looking for a way to run a python program that listens to calls from other another python program. 我正在寻找一种方法来运行python程序,以侦听来自其他另一个python程序的调用。 I tried it through the HTTP protocol, but it's very slow when heavily used. 我通过HTTP协议进行了尝试,但是使用频繁时,速度非常慢。 Is it possible to listen to memory entries that another python program writes? 是否可以监听另一个python程序编写的内存条目? Or another solution? 还是其他解决方案? Sending and retrieving calls happens on the same machine. 发送和检索呼叫发生在同一台计算机上。

Like I set up a while loop that never ends and every time looks into a file and reads it. 就像我设置了一个while循环,它永远不会结束,每次都会查看文件并读取它。

I guess database software like Google's LevelDB and MongoDB use the same method. 我猜像Google的LevelDB和MongoDB这样的数据库软件使用相同的方法。

Edit: There can be several calls at once and the script is running all the time. 编辑:一次可以有多个调用,并且脚本一直在运行。

This is a super-vague question, but if you need two processes to talk to one another, maybe you can use sockets ? 这是一个非常模糊的问题,但是如果您需要两个进程互相通信,也许可以使用套接字 You can send pickled objects through sockets or any other communication method you care to name, if that helps. 您可以通过套接字或您希望命名的任何其他通信方法发送腌制的对象,如果有帮助的话。

Are "the calls" going to be issued from the same machine? 是否要从同一台计算机发出“呼叫”?

Named pipes may be an option http://mail.python.org/pipermail/python-list/2005-March/312152.html 命名管道可能是一个选项http://mail.python.org/pipermail/python-list/2005-March/312152.html

UPD: sockets mentioned in other answer look like more appropriate way to accomplish it UPD:在其他答案中提到的套接字看起来是完成它的更合适的方法

Try the most excellent Pyro which gives you remote object calling in python: 尝试使用最出色的Pyro,它可以让您在python中调用远程对象:

http://irmen.home.xs4all.nl/pyro/ http://irmen.home.xs4all.nl/pyro/

Go straight to the simple example, which includes a server (greeting.py) which hangs around waiting for a client (client.py) to send it a message: 直接看一个简单的示例,其中包括一个服务器(greeting.py),该服务器会挂起,等待客户端(client.py)向其发送消息:

http://packages.python.org/Pyro4/intro.html#simple-example http://packages.python.org/Pyro4/intro.html#simple-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM