Python Forum
Python tailing file or named pipe stalls after a while
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python tailing file or named pipe stalls after a while
#1
I have a GNU radio project outputing data from an FM scanner running on a raspberry pi. I also have a bluetooth service running, which should send any data outputted to stdout by the gnu radio command to any receivers. The bluetooth part is working fine.

To gather data from stdout and send it to the python bluetooth script, I thought i'd use named pipes. I run this in the following manner:

sudo ais_rx --gain 44 --error 5 -s osmocom 2>&1 | sudo tee> /tmp/namedpipe
This should send both stdout en stderr to the pipe in the tmp folder, which was created on the python end like this:

pipe_path = "/tmp/namedpipe"
    if not os.path.exists(pipe_path):
        os.mkfifo(pipe_path)
I then read and print all data in a loop like this:

with open(pipe_path) as fifo:
        print("FIFO opened")
        while True:
            try:               
                data = fifo.readline()
                print(data)
            except Error:
                print ('error')
This works ok for a minute or so, and then just seems to stall. Theres no error, it just stops responding to things written to the pipe.

To rule out any problems with the pipe, I also tried writing to a file and tailing it, like this:

sudo ais_rx --gain 44 --error 5 -s osmocom 2>&1 | sudo tee> /tmp/namedfile
and I then tail it as follows:

f = subprocess.Popen(['tail','-F','/tmp/namedfile'],\
    stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    p = select.poll()
    p.register(f.stdout)

    while True:
        if p.poll(1):
            try:               
                data = f.stdout.readline().strip()            
                print(data)
            except Error:
                print ('error')
        time.sleep(1)
I know the data output doesn't actually stop, because if I tail it from a terminal I can see it coming in. It's just the python side that stops reading it.

Can anyone point me in the right direction?
Reply


Messages In This Thread
Python tailing file or named pipe stalls after a while - by nilsk123 - Jul-25-2018, 11:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Media Pipe Python Interfacing with MATLAB cmcreecc 1 169 May-30-2024, 07:23 AM
Last Post: TrentErnser
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,750 Nov-09-2023, 10:56 AM
Last Post: mg24
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,680 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  Convert Excel file into csv with Pipe symbol.. mg24 4 1,452 Oct-18-2022, 02:59 PM
Last Post: Larz60+
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,237 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  BrokenPipeError: [Errno 32] Broken pipe throwaway34 6 9,892 May-06-2021, 05:39 AM
Last Post: throwaway34
  Duplex Named Pipe with Python Server and C# Clients raybowman 1 2,483 Dec-03-2020, 09:58 PM
Last Post: Gribouillis
  2 or more processes on the write end of the same pipe Skaperen 4 4,011 Sep-27-2020, 06:41 PM
Last Post: Skaperen
  multiprocessing Pipe.poll very slow seandepagnier 0 2,421 Mar-09-2020, 03:10 AM
Last Post: seandepagnier
  ImportError: No module named pymysql - On Apache2 for Python 2.7 on Mac Tyrone 9 7,804 Jun-12-2019, 07:08 PM
Last Post: Tyrone

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020