0

We have a python 2 module that needs to be upgraded into python 3. And there is C# application in the same host will pass a large XML string data to call that python module and get the response from python by using COM Server. It works perfectly fine as py2exe supports COM Server. But py2exe is no longer available in python 3 and none of the other python releasing tool support COM Server (eg. pyinstaller). So we have to find another way.

I have tried to use Process in C#, use StandardInput to call python and on the python side, I will accept the input to get data and response to C#. It works fine but compared to the previous implementation it looks much slower.

There are some other options like Socket and expose a REST API. But for two applications on the same host, will that be overkill to use the network approach?

Kuku
  • 484
  • 8
  • 28
  • Depends on the amount of script you have planned to upgrade – eriksv88 Apr 09 '20 at 22:50
  • @eriksv88 there are three python modules, all of them are very similar in communication with C#. The C# code stands in the middle for sending and receiving a large XML data to different python modules based on the workflow settings. – Kuku Apr 09 '20 at 22:55
  • Ok, WCF is a good solution then. Or you create an Azure function. But if you haven't used much Azure. Is WCF easier to get into – eriksv88 Apr 09 '20 at 22:59
  • @eriksv88 I will have look, WCF also new to me as I'm pretty new in .net world. But does the WCF approach needs many changes on the python side? As I just need to pass in that XML data into the process function in python. – Kuku Apr 09 '20 at 23:06
  • No . use SOAP over HTTPs. – eriksv88 Apr 09 '20 at 23:10
  • See previous posting : https://stackoverflow.com/questions/61059829/call-python-scripts-with-many-dependent-libraries-from-c-sharp-code. The fastest way is what OP attempted in previous posting of using a stream (standard output to standard input). The OP believes the issue is with UNICODE characters which should not have anything to do with issue. If python 3 is running slower I believe it is a memory issue. I do no have any experience with speed comparison between python 2 & 3, put newer executable usually are larger and use more memory. – jdweng Apr 09 '20 at 23:11

1 Answers1

0

After digging a little further, it looks like you want gRPC, which is supported in both Python 3 and .NET (core and framework 4.5+):

https://grpc.io/docs/tutorials/basic/python/

https://learn.microsoft.com/en-us/aspnet/core/grpc/basics?view=aspnetcore-3.1

lmcdo
  • 45
  • 8
  • yea, the IronPython is not supporting Python 3. But unfortunately, we have to upgrade to python 3 as python 2 is no longer get maintained. – Kuku Apr 09 '20 at 23:11
  • @Kuku I've updated with what I found after digging a little bit. In short: avoid WCF -- it's not going to be supported well after .NET 5 deprecates .NET 4.8 – lmcdo Apr 09 '20 at 23:16
  • Thanks for that. The C# code is in .NET 4. Upgrading that C# app might not be a plan in the recent future. – Kuku Apr 09 '20 at 23:23
  • .NET 4 as in 4.0? Or 4.5 or later? gRPC should work in 4.5 or later. – lmcdo Apr 09 '20 at 23:29