def connect(self):
try:
self.hp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.hp.connect(self.host, self.port)
except socket.error as e:
logerr("Error: connection failed {}".format(e))
self.hp.close()
--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/1ed99eeb-426e-4c6a-a4e2-90bc2b6566ea%40googlegroups.com.
Things like this should really be run in another thread, which then communicates with the main thread. It's easy to hang, or even crash, the main thread if it is dependent on a network connection.For a fairly simple example of how this is done, look at the weewx-nmea-xdr service. On startup, it sets up a separate thread, then connects it to the main thread via a queue. The thread blocks on a serial port. When data comes in, the thread packages it, then sends it down the queue to the main thread.You can do something similar using a socket instead of a serial port.Now that I think about it, take a look around in the forums. Surely someone has done something close to what you need!-tk
On Wed, Feb 12, 2020 at 1:42 PM Tarmo <tso...@gmail.com> wrote:
--How to exit the service (to try again later) in an exception without crashing the main WeeWx process?Let's say, I want to connect to a host:def connect(self):
try:
self.hp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.hp.connect(self.host, self.port)
except socket.error as e:
logerr("Error: connection failed {}".format(e))
self.hp.close()
Now, in case of an exception, I would like to return gracefully to the main WeeWx thread without crashing it and try on the next archive interval.
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-de...@googlegroups.com.