kopia lustrzana https://github.com/glidernet/python-ogn-client
![]() When starting an AprsClient with AprsClient.run(...) the client enters a loop without an exit condition (i.e. a while True loop). If autoreconnect is set to True, it is impossible to exit the aforementioned loop even if AprsClient.disconnect() is called. This causes problems when running the client in a thread (or as a background service, etc.) as the process will not join nor terminate unless explicitly shutdown with SIGKILL. Minimal example: ``` import signal from ogn.client import AprsClient from ogn.parser import parse_aprs, parse_ogn_beacon, ParseError def process_beacon(raw_message): print('Received message') client = AprsClient(aprs_user='N0CALL') signal.signal(signal.SIGTERM, lambda signo, stackno: client.disconnect()) client.connect() client.run(callback=process_beacon, autoreconnect=True) ``` This commit fixes such issues by adding a kill flag that is raised when calling AprsClien.disconnect() to the while conditions of both loops inside AprsClient.run(). Note: the outermost loop could still remain a while True loop as the exit condition is checked at the end of the loop body. |
||
---|---|---|
ogn | ||
tests | ||
.gitignore | ||
.travis.yml | ||
CHANGELOG.md | ||
CONTRIBUTORS | ||
LICENSE | ||
MANIFEST.in | ||
README.md | ||
requirements.txt | ||
setup.cfg | ||
setup.py |
README.md
python-ogn-client
[]
(https://travis-ci.org/glidernet/python-ogn-client)
[
]
(https://pypi.python.org/pypi/ogn-client)
[
]
(https://coveralls.io/github/glidernet/python-ogn-client?branch=master)
A python3 module for the Open Glider Network. It can be used to connect to the OGN-APRS-Servers and to parse APRS-/OGN-Messages.
A full featured gateway with build-in database is provided by ogn-python.
Example Usage
Parse APRS/OGN packet.
from ogn.parser import parse_aprs, parse_ogn_beacon
from datetime import date, time
beacon = parse_aprs("FLRDDDEAD>APRS,qAS,EDER:/114500h5029.86N/00956.98E'342/049/A=005524 id0ADDDEAD -454fpm -1.1rot 8.8dB 0e +51.2kHz gps4x5",
reference_date=date(2016,1,1), reference_time=time(11,46))
beacon.update(parse_ogn_beacon(beacon['comment']))
Connect to OGN and display all incoming beacons.
from ogn.client import AprsClient
from ogn.parser import parse_aprs, parse_ogn_beacon, ParseError
def process_beacon(raw_message):
if raw_message[0] == '#':
print('Server Status: {}'.format(raw_message))
return
try:
beacon = parse_aprs(raw_message)
beacon.update(parse_ogn_beacon(beacon['comment']))
print('Received {beacon_type} from {name}'.format(**beacon))
except ParseError as e:
print('Error, {}'.format(e.message))
client = AprsClient(aprs_user='N0CALL')
client.connect()
try:
client.run(callback=process_beacon, autoreconnect=True)
except KeyboardInterrupt:
print('\nStop ogn gateway')
client.disconnect()
License
Licensed under the AGPLv3.