Simon
Simon

Reputation: 514

How to check if subprocess is polling, but not receiving data

I use subprocess.popen command to scan a frequency.

My programm receives data, but, I am having difficulties to detect 'the end of a message'.

So, I am looking for the code how to check if the .poll() command is polling, but not receiving data.

As far as I have found with google, line should be '' when no data received, and just once, the program responded by printing several empty lines. Unfortunately, this was only once, but, that could be what I am looking for. Meaning, 2 or 3 empty lines will probably also indicate there is no data to be received.

multimon_ng = subprocess.Popen("rtl_fm -f 169.65M -M fm -s 22050 -p 43 -g 30 | multimon-ng -a FLEX -t raw -",
  stdout = subprocess.PIPE,
  stderr = open('error.txt', 'a'),
  shell = True)

while True:
  multimon_ng.poll()
line = multimon_ng.stdout.readline()
print(line)

How to check if subprocess is polling?

Upvotes: 0

Views: 285

Answers (1)

Artfunkel
Artfunkel

Reputation: 1852

If the process is still running, poll() will return None. Otherwise it will return the exit code. (From the docs)

However, I'm not sure that will help you here:

  • If you want to wait until the process exits, just make a single call to wait() instead of using poll().
  • If you want to keep the program running and respond to multiple messages across its lifetime then you are going to need to know exactly what an "end of message" signal looks like, call stdout.readline() in a loop, and detect and handle that signal without exiting that loop.

Upvotes: 1

Related Questions