Skip to content
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 working pyzmq socket support #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

remleduff
Copy link

Just pushing the cart a little further. This at least seems to be basically functional.

Am I missing anything you can see immediately?

I'd ignored what would happen if there were multiple send tasks waiting
Copy link
Member

@njsmith njsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One substantive question, but overall yeah this all looks reasonable!

Obviously to make a "real" package we also need tests and docs, and probably to wrap a bit more of the zmq API (e.g. Socket.setsockopt).

Are you planning to keep going, or was this more of just an exercise to see if you could make it work? If the latter that's cool, but then we should probably update the README a bit to explain the new status before leaving it for the next person :-).

await trio.lowlevel.wait_readable(self._zmq_sock.fd)
finally:
self._someone_is_watching_trigger = False
self._update_events()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code had wake_all=True here and a comment explaining why -- is that still needed or are you handling that somewhere else somehow?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had convinced myself it wasn't needed, because the rule is that anyone who wakes up will do whatever they wanted to do and then call _update_events.

I was just writing an example to show that was right, and instead I think I've come up with an example that DOES need wake_all, so I guess I'm wrong.

If all the waiters are wanting to write: one will end up watching the trigger and one will end up sleeping. If the watcher wakes up, it will do its write, and then call _update_events which doesn't wake up the other waiter, and now no one is listening for the trigger.

In short, I think you're right and I should add it back.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's not correct.

In that example the other waiter would be awoken (the event is broadcast to all of the same type of waiters) and end up as the next watcher when it discovers the socket isn't writable anymore.

So that means the case of "watcher and waiter are the same type" is ok.

For the case of "watcher and waiter are of different types". The watcher will wake up: if the event matches the waiter, it's obviously ok because the watcher will go back to watching. If the event matches the watcher, the watcher will leave _wait_for and temporarily no one is watching the trigger. The watcher then does whatever it wanted to do and then calls _update_events.

My assertion is that this will always cause the waiter to be awoken (if the watcher wrote, then the waiter must have been waiting for a message, and it will now see that there is one to read. If the watcher read, then the waiter must have been waiting for space to write a message and it will now be available.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that taking into account that the reason the watcher might wake up is b/c they were cancelled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants