Addition of threading

Associated with https://github.com/emonhub/emonhub/issues/66
These are the changes required to add threading. Il try and write it up next