Async tcp server#68
Closed
bradder555 wants to merge 5 commits into
Closed
Conversation
a blocking server is handy if there is a background thread mutating memory, or if we are only interested in mutating this memory through modbus to expand the functionality a little bit, an async option has been added, this fires up the server on a background thread freeing up the forground (or alternative thread) to modify the block of memory. this is nice, because the application can now be used to simulate a plc or rio in one process currently this pattern only works with the TcpSocket server, it would be nice to expand this further to provide the same interface for the serial class
asynchronicity has been added to the modbus tcp server, this adds an example to the readme to demonstrate how to use these changes
1fedb6d to
e85cb5e
Compare
the async server is added to the tests in order to maintain test coverage
2.7 doesn't like the syntax:
def __init__(self, server_address, request_handler):
super().__init__(server_address, request_handler)
since i don't need to use super, it's an easy fix to delete these two
lines
OrangeTux
reviewed
Mar 6, 2019
Collaborator
There was a problem hiding this comment.
Thanks for your PR! I see the need for non-blocking server, but I don't think adding special support for it is a bit overkill. You can just use the code you wrote in the start_async()method inside the main handler:
# do imports
app = get_server(TCPServer, ('localhost', 502), RequestHandler)
# Configure handlers
if __name__ == '__main__':
try:
t = Thread(target=app.serve_forever)
t.daemon = True
t.start()
for i in range(10):
print(i)
sleep(1)
finally
app.shutdown()
app.server_close()
t.join()This has several advantages:
- doesn't add complexity to uModbus API
- work consistent with both RTU and TCP servers
There I won't accept the PR.
On a side note: the term async is often used to refer to asyncio, which is different programming paradigm than threads, which you use in your PR.
Author
|
words have meaning outside of pythonland: I can appreciate how the use of async can be confusing |
hmaerki
pushed a commit
to hmaerki/obsolete-fork-uModbus
that referenced
this pull request
Dec 31, 2023
This file contains hidden or 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
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.
a blocking server is handy if there is a background thread mutating
memory, or if we are only interested in mutating this memory through modbus
to expand the functionality a little bit, an async option has been added,
this fires up the server on a background thread freeing up the forground
(or alternative thread) to modify the block of memory.
this is nice, because the application can now be used to simulate a plc
or rio in one process
currently this pattern only works with the TcpSocket server, it would be nice
to expand this further to provide the same interface for the serial class