最简单的方法使用IPC Python和C#之间的沟通? [英] Simplest way to communicate between Python and C# using IPC?

查看:464
本文介绍了最简单的方法使用IPC Python和C#之间的沟通?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要调用一个Python脚本几千次,每次传递一个字符串,然后期待一个浮动背一些​​C#代码。 Python脚本可以使用Python的任何版本上运行,所以我不能用铁蟒蛇。它已经建议我使用IPC命名管道。我有这样的经验,和我有麻烦搞清楚如何C#和Python之间做到这一点。这是一个简单的过程,还是我找工作,像样的数目?这是解决我的问题的最好方法是什么?

I have some C# code that needs to call a Python script several thousand times, each time passing a string, and then expecting a float back. The python script can be run using ANY version of Python, so I cannot use Iron python. It's been recommended that I use IPC named pipes. I have no experience with this, and am having trouble figuring out how to do this between C# and Python. Is this a simple process, or am I looking at a decent amount of work? Is this the best way to solve my problem?

推荐答案

使用zeromq。


  • 允许很轻的消息,而不需要经纪人

  • 可用于许多平台

  • 可以通过TCP通讯插座,Unix套接字或一个进程内的

下面是我的回答使用zeromq的 http://stackoverflow.com/a/23227631/346478

Here is my answer using zeromq http://stackoverflow.com/a/23227631/346478

,供应不同的Python程序之间的消息传递,但究竟可以在其他平台之间使用的通信方法相同。只要保持周围interopable传递的消息 - 双方必须正确理解的内容。你可以用二进制数据玩,但很多时候JSON表示工作快速和容易了。但也有类似结果缓冲区和其他许多序列化框架,它可以帮助您进行编码的结果。

It serves for messaging between different Python programs, but exactly the same method of communication can be used between other platforms. Just keep the messages passed around interopable - both sides must understand the content properly. You can play with binary data, but very often json representation work quick and easy too. But there are many serialization frameworks like result buffers and others, which might help you to encode result.

这篇关于最简单的方法使用IPC Python和C#之间的沟通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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