1

I need a way for c# to communicate with an arbitrary version of Python. The user passes in a path to Python, so they can choose any version they want. I need to be able to pass a string to Python, and get back a float. This needs to happen several thousand times. Right now i'm just using standard in/out, but it seems to be very slow. Is there any faster way to do this?

user3490130
  • 103
  • 1
  • 1
  • 5

2 Answers2

5

Typically, the "best" way to handle this type of scenario is to use IronPython instead of having the user supply their own Python runtime.

You can also use Python for .NET, but this again will tie you to a specific version of Python.

If you control what's called in Python, but need arbitrary versions of python, you may be able to use a common messaging service. One option would be to setup an IPC channel via pipes, which are supported in Python and .NET. This would provide fast C#->Python->C# communication while keeping the process separate.

If you need arbitrary versions and installations of python, than executing and fetching information via the shell process may be the only option.

Victor Uriarte
  • 479
  • 4
  • 9
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
0

Very fast is using zmq, libraries are available for both, C# and Python, can talk across network, in some situations is faster then plain TCP.

E.g. iPyhton is using it for internal inter-component communication.

My StackOverflow answer shows Lock server implemented over zmq which could be used to serve C# too.

Community
  • 1
  • 1
Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98