Blinkt processing overhead

Hello! Looking for some general tuning feedback on the Blinkt module. Using the example code for the twitter_monitor in a RPi0W environment, I observed <50% CPU utilization (panel view) for two hashtags. In this mode I wrote the tweet to a text file. When I embellish the code to light up Blinkt, the CPU utilization is pegged to the maximum (sustained 100%).

		def on_data(self, data):
			self._f.write(data)		# log the data for post-processing analysis
									# blink the LED with corresponding colors
				json_str = json.loads(data)
				for j in json_str['entities']['hashtags']:
					for k in hashtags:
						if j['text'].lower() in k.lower():
							l = hashtags.index(k)
							r, g, b = colors[l]
							blink_blinkt(1, r, g, b)
			except BaseException as e:
				print("Data write error: %s" % str(e))
			return True

Any guidance on how to tweak the code (reduce the pre-processing for Blinkt display) so that the CPU time can become a little more hospitable for other background tasks. I am not receiving any Twitter IncompleteRead messages anymore (after saving the file handler as a local variable) but perhaps my code leaves a lot to be desired. I feel that something else is going on here since even when the lights are not blinking there is no perceptible drop in the CPU utilization number (from 100 in the panel view).


Perhaps you could use something like to link twitter to a webhook to get notifications instead to avoid having to parse a lot of unnecessary json directly?

Thanks! I’ll look into it. I have also started testing “profile” modules. Rgds.