jim-easterbrook / pywws

Python software for USB Wireless WeatherStations
https://pywws.readthedocs.io/
GNU General Public License v2.0
204 stars 63 forks source link

Should use async calls for plotting and data publishing #9

Closed 3v1n0 closed 10 years ago

3v1n0 commented 11 years ago

Pywws is meant to be used in low-powered devices, but gnuplot is not.

Right now enabling plots causes pywws to wait the plotter to have finished its task before continuing with its duties, I think it should instead using a thread to detach from gnuplot and using a callback function once completed (i.e. using something like http://stackoverflow.com/a/2581943/210151)

Having the same for network actions would be a plus.

jim-easterbrook commented 11 years ago

You'd really want a separate 'processing' (or tasks) thread to do this, as there are typically a bunch of plots to be done sequentially, followed by an upload. To keep life simple the processing thread wouldn't have access to the data stores, so the files to be plotted would need to be created in the main thread, then their details handed to the processing thread. I like to use queues for this sort of thing, rather than callbacks. The processing thread would just take tasks off the queue one by one, do them, and then sleep when the queue's empty.

3v1n0 commented 11 years ago

Oh, yes... Can be done also like this. Keeping all this stuff into the Tasks thread. But I think it's inconvenient to do all in order as it's done now, since it causes the livedata to be ignored for a while until CPU is ready...

jim-easterbrook commented 11 years ago

You misunderstand - I'm not suggesting holding everything up while the plots are done (although I don't have a problem with ignoring live data for a minute or two) but you need to make sure you don't try and do half a dozen plots concurrently. So each plot needs to start after the previous one finishes, i.e. a queue.

3v1n0 commented 11 years ago

Ah, sure... Keeping the order was intended.

jim-easterbrook commented 11 years ago

I'll have a go at doing this, probably in a week or two after the next "release".

jim-easterbrook commented 11 years ago

I've done a first go at using an uploads queue in commit ff6561. I'll add the 'service' uploads next.