Interprocess c # python in real time

I am working on a project in which I will have one application in C # and another in Python. The C # application will continuously analyze the data stream and raise the flag every time something interesting is discovered. Therefore, every time there is an event, my Python application will have to read it and continue with its own process, while other flags will continue to be sent. As you can imagine, a C # application does not wait for Python to complete the calculation before sending another flag.

So I was wondering if it is possible to create sub / pub (C #, which is the publisher and Python subscriber), if so, how can I do this and you think this is a good idea? I am new to this area, so could you tell me if there are other possibilities?

Thanks for your help.

+5
source share
3 answers

The simplest way is PIPEcommunication. another simple way that is not suggested is programming SOCKET. Pipes and named pipes are a good solution for exchanging data between different processes (in different programming languages). SOCKETprogramming is similar to this, but may require more access and may be less security.

another type of IPC seems unusable.

see additional information:

+2
source

Redis pub / sub is awesome ... or ZeroMQ .

+4
source

You can use aktos-dcs and aktos-dcs-cs libraries. I have successfully used these libraries in production so that the RFID Reader (from Impinj) communicates with (actually, integrated) our telemetry system. The RFID reader has a C # API, and we use Python heavily in our telemetry system.

The simplest test case is a ping-pong application, and here is what it looks like with these libraries:

pinger.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using aktos_dcs_cs;

namespace pinger
{
    class Pinger : Actor
    {
        public void handle_PingMessage(Dictionary<string, object> msg)
        {
            Console.WriteLine("Pinger handled PingMessage: {0} ", msg["text"]);

            string msg_ser = @"
                    {""PongMessage"": 
                        {""text"": ""this is proper message from csharp implementation""}
                    }
                ";
            System.Threading.Thread.Sleep(2000);
            send(msg_ser);
        }

    }


    class Program
    {
        static void Main(string[] args)
        {
            Pinger x = new Pinger(); 
            Actor.wait_all(); 
        }
    }
}

ponger.py:

from aktos_dcs import *

class Pinger(Actor):
    def handle_PingMessage(self, msg_raw):
        msg = get_msg_body(msg_raw)
        print "Pinger got ping message: ", msg['text'], (time.time() - msg_raw['timestamp'])
        sleep(2)
        self.send({'PongMessage': {'text': "Hello ponger, this is pinger 1!"}})

if __name__ == "__main__":
    ProxyActor()
    pinger = Pinger()
    pinger.send({'PongMessage': {'text': "Hello ponger, this is STARTUP MESSAGE!"}})

    wait_all()
0
source

All Articles