mirror of
https://github.com/KevinMidboe/homeChecker.git
synced 2025-10-29 17:40:26 +00:00
Added logger and wrapped while loop in a try/except and log any errors.
This commit is contained in:
@@ -2,12 +2,16 @@
|
|||||||
from socket import *
|
from socket import *
|
||||||
from macLookup import getTimes
|
from macLookup import getTimes
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Define the socket communicating will transfered
|
# Define the socket communicating will transfered
|
||||||
serverSocket = socket(AF_INET, SOCK_DGRAM)
|
serverSocket = socket(AF_INET, SOCK_DGRAM)
|
||||||
serverSocket.bind(('', 12001))
|
serverSocket.bind(('', 12001))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
# Save the message and return address to variables.
|
# Save the message and return address to variables.
|
||||||
message, address = serverSocket.recvfrom(1024)
|
message, address = serverSocket.recvfrom(1024)
|
||||||
|
|
||||||
@@ -16,4 +20,6 @@ while True:
|
|||||||
times = json.dumps(getTimes())
|
times = json.dumps(getTimes())
|
||||||
# This should prob be cases and not if's, but works to get the right info user requests.
|
# This should prob be cases and not if's, but works to get the right info user requests.
|
||||||
serverSocket.sendto(bytes(times, 'utf-8'), address)
|
serverSocket.sendto(bytes(times, 'utf-8'), address)
|
||||||
|
# serverSocket.close()
|
||||||
|
except Exception as e:
|
||||||
|
log.info(e.message, e.args)
|
||||||
|
|||||||
Reference in New Issue
Block a user