1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-06-24 21:15:18 -04:00

more debugging messages trying to find rare tight loop in main

This commit is contained in:
craigerl 2020-12-06 08:59:33 -08:00
parent 85b17c3398
commit 3d7e3a4e54

View File

@ -212,8 +212,8 @@ def _imap_connect():
host, host,
imap_port imap_port
)) ))
LOG.debug("Connect to IMAP host {} with user '{}'". # LOG.debug("Connect to IMAP host {} with user '{}'".
format(msg, CONFIG['imap']['login'])) # format(msg, CONFIG['imap']['login']))
try: try:
server = imapclient.IMAPClient(CONFIG['imap']['host'], port=imap_port, server = imapclient.IMAPClient(CONFIG['imap']['host'], port=imap_port,
@ -222,7 +222,7 @@ def _imap_connect():
LOG.error("Failed to connect IMAP server") LOG.error("Failed to connect IMAP server")
return return
LOG.debug("Connected to IMAP host {}".format(msg)) # LOG.debug("Connected to IMAP host {}".format(msg))
try: try:
server.login(CONFIG['imap']['login'], CONFIG['imap']['password']) server.login(CONFIG['imap']['login'], CONFIG['imap']['password'])
@ -231,7 +231,7 @@ def _imap_connect():
LOG.error("Failed to login {}".format(msg)) LOG.error("Failed to login {}".format(msg))
return return
LOG.debug("Logged in to IMAP, selecting INBOX") # LOG.debug("Logged in to IMAP, selecting INBOX")
server.select_folder('INBOX') server.select_folder('INBOX')
return server return server
@ -350,7 +350,7 @@ def check_email_thread():
check_email_delay = 60 check_email_delay = 60
while True: while True:
LOG.debug("Top of check_email_thread.") # LOG.debug("Top of check_email_thread.")
time.sleep(check_email_delay) time.sleep(check_email_delay)
@ -380,12 +380,12 @@ def check_email_thread():
continue continue
messages = server.search(['SINCE', today]) messages = server.search(['SINCE', today])
LOG.debug("{} messages received today".format(len(messages))) #LOG.debug("{} messages received today".format(len(messages)))
for msgid, data in server.fetch(messages, ['ENVELOPE']).items(): for msgid, data in server.fetch(messages, ['ENVELOPE']).items():
envelope = data[b'ENVELOPE'] envelope = data[b'ENVELOPE']
LOG.debug('ID:%d "%s" (%s)' % # LOG.debug('ID:%d "%s" (%s)' %
(msgid, envelope.subject.decode(), envelope.date)) # (msgid, envelope.subject.decode(), envelope.date))
f = re.search(r"'([[A-a][0-9]_-]+@[[A-a][0-9]_-\.]+)", f = re.search(r"'([[A-a][0-9]_-]+@[[A-a][0-9]_-\.]+)",
str(envelope.from_[0])) str(envelope.from_[0]))
if f is not None: if f is not None:
@ -661,6 +661,7 @@ def main(args=args):
# ACK (ack##) # ACK (ack##)
if re.search('^ack[0-9]+', message): if re.search('^ack[0-9]+', message):
LOG.debug("ACK")
# put message_number:1 in dict to record the ack # put message_number:1 in dict to record the ack
a = re.search('^ack([0-9]+)', message) a = re.search('^ack([0-9]+)', message)
ack_dict.update({int(a.group(1)): 1}) ack_dict.update({int(a.group(1)): 1})
@ -668,6 +669,7 @@ def main(args=args):
# EMAIL (-) # EMAIL (-)
# is email command # is email command
elif re.search('^-.*', message): elif re.search('^-.*', message):
LOG.debug("EMAIL")
searchstring = '^' + CONFIG['ham']['callsign'] + '.*' searchstring = '^' + CONFIG['ham']['callsign'] + '.*'
# only I can do email # only I can do email
if re.search(searchstring, fromcall): if re.search(searchstring, fromcall):
@ -711,6 +713,7 @@ def main(args=args):
# TIME (t) # TIME (t)
elif re.search('^[tT]', message): elif re.search('^[tT]', message):
LOG.debug("TIME")
stm = time.localtime() stm = time.localtime()
h = stm.tm_hour h = stm.tm_hour
m = stm.tm_min m = stm.tm_min
@ -723,12 +726,14 @@ def main(args=args):
# FORTUNE (f) # FORTUNE (f)
elif re.search('^[fF]', message): elif re.search('^[fF]', message):
LOG.debug("FORTUNE")
process = subprocess.Popen(['/usr/games/fortune', '-s', '-n 60'], stdout=subprocess.PIPE) process = subprocess.Popen(['/usr/games/fortune', '-s', '-n 60'], stdout=subprocess.PIPE)
reply = process.communicate()[0] reply = process.communicate()[0]
send_message(fromcall, reply.rstrip()) send_message(fromcall, reply.rstrip())
# PING (p) # PING (p)
elif re.search('^[pP]', message): elif re.search('^[pP]', message):
LOG.debug("PING")
stm = time.localtime() stm = time.localtime()
h = stm.tm_hour h = stm.tm_hour
m = stm.tm_min m = stm.tm_min
@ -738,6 +743,7 @@ def main(args=args):
# LOCATION (l) "8 Miles E Auburn CA 1771' 38.91547,-120.99500 0.1h ago" # LOCATION (l) "8 Miles E Auburn CA 1771' 38.91547,-120.99500 0.1h ago"
elif re.search('^[lL]', message): elif re.search('^[lL]', message):
LOG.debug("LOCATION")
# get last location of a callsign, get descriptive name from weather service # get last location of a callsign, get descriptive name from weather service
try: try:
print("XXX message is:" + message) print("XXX message is:" + message)
@ -773,6 +779,7 @@ def main(args=args):
# WEATHER (w) "42F(68F/48F) Haze. Tonight, Haze then Chance Rain." # WEATHER (w) "42F(68F/48F) Haze. Tonight, Haze then Chance Rain."
elif re.search('^[wW]', message): elif re.search('^[wW]', message):
LOG.debug("WEATHER")
# get my last location from aprsis then get weather from # get my last location from aprsis then get weather from
# weather service # weather service
try: try:
@ -804,12 +811,14 @@ def main(args=args):
# USAGE # USAGE
else: else:
LOG.debug("USAGE")
reply = "Usage: weath, locate <callsign>, ping, time, fortune" reply = "Usage: weath, locate <callsign>, ping, time, fortune"
send_message(fromcall, reply) send_message(fromcall, reply)
# let any threads do their thing, then ack # let any threads do their thing, then ack
time.sleep(1) time.sleep(1)
# send an ack last # send an ack last
LOG.debug("SEND ACK")
send_ack(fromcall, ack) send_ack(fromcall, ack)
except Exception as e: except Exception as e:
@ -822,13 +831,13 @@ def main(args=args):
sock.close() sock.close()
setup_connection() setup_connection()
sock.send("user %s pass %s vers https://github.com/craigerl/aprsd 2.00\n" % (user, password)) sock.send("user %s pass %s vers https://github.com/craigerl/aprsd 2.00\n" % (user, password))
LOG.debug("continue: connection fail") LOG.debug("continue: connection failed, just reconnected")
continue continue
# LOG.error("Exiting.") # LOG.error("Exiting.")
# os._exit(1) # os._exit(1)
time.sleep(5) time.sleep(5)
LOG.debug("contnue: don't know what failed: " + str(e)) LOG.debug("contnue: Unexpected error: " + str(e))
continue # don't know what failed, so wait and then continue main loop again continue # don't know what failed, so wait and then continue main loop again
LOG.debug("Main loop end") LOG.debug("Main loop end")