I'm using a named pipe FIFO to communicate between a C ( a loop generating numbers is C) and python (listening to the number generated by C and read them and process them). The code working well except for each generated number in C i need to close the fifo to be able to see it in Python, otherwise it won't be shown in python till a close command is called. I don't know if opening and closing FIFO is a good idea to be able to read them correctly in python code or not. I need to note that the C code generates number every 50 millisecond. This is why I doubt opening and closing is a good idea or not. Here are my codes in C and Python:
C as Server:
while (1){
            t=time_in_ms();
            if (t-t0>=50){
                    t0=t;
                    flag=1;
            }
            else{
                    flag=0;
            }
            if (flag==1){
                    flag=0;
                    printf("%lld %lld\n",count,t);
                    count+=1;
                    fprintf(f,"%lld\r",t);
                    fflush(f);
                    fclose(f);
                    f=fopen("fifo","w");
            }
    }
And Code in Python as Client:
with open(FIFO) as fifo:
print("FIFO opened")
while True:
    data = fifo.read()
    if len(data) == 0:
            count=count+1
    else:
            count=0
    if count>2000:
        print("Writer closed")
        break
    print data
    x=x+1
 
    