-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add socket event monitor capability #50
Conversation
@@ -194,3 +215,36 @@ def msg_received(self, data): | |||
|
|||
data is the multipart tuple of bytes with at least one item. | |||
""" | |||
|
|||
MonitorEvents = {zmq.EVENT_ACCEPTED: 'accepted', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use enum here
I support the idea in general but propose a bit another interface.
I believe hiding monitor socket from library user makes public API easy and clean. |
This change hides most of the event monitor details from the user. The event monitor can be enabled by calling This took a while to get going because I encountered a confusing problem obtaining the socket event messages when running within the event loop. Using standard |
Looks like I have a few CI issues to resolve, I'll push a change to fix this soon. |
It looks like I have a CI problem remaining - "connection refused". I can't replicate this locally using OSX or Linux (Ubuntu 14.04). Have you encountered issues that only show up on TravisCI? Can you recommend any debugging strategies for this kind of problem (otherwise, I'm stuck with trial and error)? |
It looks like the last CI issue I had was related to the TravisCI test environment using libzmq3. In my test environments I am using a more recent version of libzmq (libzmq4). I think this explains why it works in my test environments (OSX and linux on machines at home and at work) but not on TravisCI. The socket monitor capability was only really added in libzmq>=4 and pyzmq>=14.4. I have added runtime checks so that the library remains compatible with operating on libzmq3 (though without a socket monitoring capability) and can provide the monitoring capability when operating on libzmq4. It might be time to revise the |
I consider this change complete now and ready for your review. Unfortunately the latest TravisCI builds indicate failure but I think this status is erroneous. Two builds succeed and then I pushed a docs-only change which resulted in a broken build. I subsequently pushed a trivial change to re-trigger a Travis rebuild and again this produced a failure but in a different builder. I consider this a TravisCI issue, not a problem with the docs change that was last delivered. As owner of this repo you could manually re-trigger a TravisCI build to re-check the build status to confirm if this is a TravisCI issue or a real code issue. You can do this by opening the TravisCI page and clicking on the rebuild icon. Details can be found here. |
@asvetlov could you manually bump TravisCI to perform another build? See above comment for details. |
|
||
This method is only called when a socket monitor is enabled. | ||
|
||
:param event: A dict containing the event description keys `event`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike dict
(yes, it's supported by zmq.utils.monitor.parse_monitor_message()
but we may repeat these 6 lines of code.
My suggestion is using namedtuple
instead.
It looks like TravisCI fell over again running this docs-only update. Perhaps you could manually re-trigger the TravisCI build again? |
Eah, Travis is pretty unstable for the last year. |
I like the PR but please write additional tests. |
|
||
def msg_received(self, data): | ||
if len(data) != 2 or len(data[0]) != 6: | ||
raise RuntimeError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not test covered
@@ -693,6 +776,8 @@ def close(self): | |||
def _force_close(self, exc): | |||
if self._conn_lost: | |||
return | |||
if self._monitor: | |||
self.disable_monitor() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not covered
I have added test coverage for the monitor additions. While I was looking at the coverage output I noticed some areas that could be updated to improve the coverage so I did that too (e.g. test supplying an external zmq context, get_write_buffer_limits) to improve the existing test coverage. These were in the vicinity of the areas I was updating anyway. |
Add socket event monitor capability
Thanks! |
Would you take a look on adding events monitoring to stream API? |
This pull request adds the ZMQ socket event monitor capability to aiozmq.
I am using this in my system which uses ephemeral ports. I use it to detect client disconnects, then tear down the socket, use a discovery mechanism to resolve the new endpoint address and finally re-establish the socket.