0

I haven't been able to find any gpsd examples that do not do something similar to Python GPS Module: Reading latest GPS Data. Using multiprocessing I wrote a Process that handles reading gps data from a device with the following inside run(). NOTE, I want to be able to stop this process so I cannot use just the next() function of the gps session as it is a blocking call:

# connect to gpsd
g = gps.gps('127.0.0.1',2947)
g.stream(gps.WATCH_ENABLE)

while True:
    try:
         if poisonpillq.get_nowait() == '!STOP!': break
    except Queue.Empty:
        if g.waiting():
            rpt = g.next()
            if rpt['class'] == 'TPV':
                --- store_gps_data from rpt/g ---

Doing this, my CPU hits 100%. Testing CPU usage with program xpgs, the CPU hits at max 15% usage. So how can this usage be circumvented?

Community
  • 1
  • 1
WraithWireless
  • 634
  • 9
  • 21

1 Answers1

0

Adding a "poll" time cut usage down. Like this:

# connect to gpsd
g = gps.gps('127.0.0.1',2947)
g.stream(gps.WATCH_ENABLE)

while True:
    try:
         if poisonpillq.get(True,polltime) == '!STOP!': break
    except Queue.Empty:
        while g.waiting():
            rpt = g.next()
            if rpt['class'] == 'TPV':
                --- store_gps_data from rpt/g ---

With a poll time of 0.5, CPU usage never hits more than 20%. With a poll time of 3.0, the CPU usage maxes out at around 17%.

This is not a perfect solution. Since the gps transfer is serial, the longer the process blocks on the poison pill queue, the more data needs to be read, meaning the caller may have to wait a "long" time before the gps Process gets the poison pill. Additionally, is it possible that there could always be data and the gps Process will never get the poison pill queue?

WraithWireless
  • 634
  • 9
  • 21