Simplest way to communicate between Python and C# using IPC?

為{幸葍}努か 提交于 2020-01-10 04:22:11

问题


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?


回答1:


Use zeromq.

  • allows very light messaging without a need for broker
  • is available for many platforms
  • can communicate over TCP socket, unix socket or inside a process

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

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.



来源:https://stackoverflow.com/questions/23374854/simplest-way-to-communicate-between-python-and-c-sharp-using-ipc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!