-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emon pi develop #38
Merged
Merged
Emon pi develop #38
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
except on it's own catches all exceptions!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes @beaylott's "Thread exception reporting, thread restarting, restart counting..." changes and a native message queue implementation outlined by @pb66 in response to threading issues in the emon-pi variant of emonhub.
Explanation of native message queue
In order to move data between the interfacers in emonhub e.g data received by the JeeLib interfacer and then published by the MQTT interfacer, emonhub has been using a python library called pydispatcher.
I had thought that it was a neat solution, moving data between threads with the ease of use similar to MQTT. However @pb66 highlighted that there was an issue with the implementation, that the intention of one thread per interfacer was not being preserved, the MQTT interfacer in particular was actually running in the RFM2Pi thread!
Paul then described a solution that would remove the need for the external pydispatcher library with a simple native message queue implementation. Here is my attempted summary (with references to the lines of code that implement it):
We start with the main thread (in emonhub.py)
The main thread starts a scan of each interfacer (L143)
The main thread finds a pubchannel on the RFM2Pi interfacer called 'ToEmonCMS' (L149)
The main thread reads and removes one item from the 'ToEmonCMS' queue on the RFM2Pi interfacer. (L155)
The main thread iterates through each interfacer looking for subchannel entries called 'ToEmonCMS' (L158-L162)
The main thread posts a copy of the item read from RFM2Pi into the 'ToEmonCMS' queue on each subscribing interfacer. (L168)
The subscribing interfacer then reads and acts on the queue in its own time and in its own thread.
The main thread then goes on to the next interfacer checking its pubchannel's, repeating steps 4 to 6 above.
A single item is read at a time in order to avoid the case where a runaway interfacer monopolizes the main thread which could block the other interfacers, it also allows for the simple use of pop and append.
The implemented result in this pull request fixes the threading issue that was present in the pydispatcher based implementation while reducing emonhub's dependencies, thanks to @pb66 for the idea and description of how to implement.