From 0194577f43a29b96d16c211399f5fda7a8c898fa Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 2 Apr 2021 15:10:18 -0700 Subject: [PATCH] Better reuse of object with Adafruit IO --- adafruit_portalbase/network.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index 955a322..21255fa 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -110,6 +110,8 @@ def __init__( except OSError: self.uselocal = False + self._io_client = None + gc.collect() def neo_status(self, value): @@ -341,8 +343,12 @@ def connect(self): print("Could not connect to internet", error) print("Retrying in 3 seconds...") time.sleep(3) + gc.collect() def _get_io_client(self): + if self._io_client is not None: + return self._io_client + self.connect() try: @@ -353,7 +359,8 @@ def _get_io_client(self): "Adafruit IO secrets are kept in secrets.py, please add them there!\n\n" ) from KeyError - return IO_HTTP(aio_username, aio_key, self._wifi.requests) + self._io_client = IO_HTTP(aio_username, aio_key, self._wifi.requests) + return self._io_client def push_to_io(self, feed_key, data): """Push data to an adafruit.io feed