-
Notifications
You must be signed in to change notification settings - Fork 645
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
ZMQStream.on_recv/on_send should pass stream to callbacks #166
Comments
What about implementing new callbacks with different names? Something like on_recv_wstream/on_send_wstream. The ZMQStream object could look to see which pair of callbacks is registered and call those only. That allows existing apps to keep using the on_recv/on_send ones, and migrate when they are ready. |
A new method is probably the best approach, though a clearly temporary name like 'on_recv_wstream' would not be ideal. |
Another thing that's different about the czmq reactor (and one of the reasons it passes stream) is that it does not call recv itself, but rather passes |
That makes the callback a little lower level though and forces the On Fri, Jan 20, 2012 at 11:29 AM, Min RK
Brian E. Granger |
Correct. I have encountered one or two cases where things would have been a bit simpler if I could call recv myself, rather than having the message, but I don't think that's an actual problem. This would make zmqstream more similar to tornado's own IOStream class (i.e. just use the add_handler level of code, rather than the higher level on_recv, etc.) |
Yes, it would make it more like the IOStream class if we required the On Fri, Jan 20, 2012 at 11:43 AM, Min RK
Brian E. Granger |
What I really want is on_recv to pass two arguments instead of one, with no other changes, and the most graceful path ahead for that. The rest is merely presenting further alternatives that could be considered, but are not actually what I am aiming for. It's possible that simply Users who want a low-level mode can simply use Sockets with |
OK, I like the idea of having the new methods get the stream and the On Fri, Jan 20, 2012 at 2:59 PM, Min RK
Brian E. Granger |
Hi! The plain 2 at the end doesn't have any meaning, as shown in the arguments so far. There are methods with longer names and they don't hurt, like recv_multipart etc. Cheers |
The old (no, not normal) on_recv methods gave no information, so the new descriptive name is only informative if you already understand on_recv. The reason why I dislike adding a qualifier to the name is that the new methods are meant to replace the old ones, as a year and a half of writing apps with them has proven to me that this is how they should have been written in the first place. The only reason they are separate is so that I don't break existing apps while users upgrade. That is less likely to take hold if the new name suggests that it is a bonus version, rather than the replacement that it is. That said, maybe the best approach is to let it be, and use a more descriptive name, leaving the original bad decision in forever.
|
Hi from frozen Germany! Hmmm... given the time pyzmq is in use and the number of users I've seen (irc mostly) I'd say: A new (better) way using new methods will be the only way I guess. Anyway, the new way is of course better and does make some things much easier. Cheers |
@guidog: how are you using PyZMQ in python-mdp? |
@ellisonbg They way it should be used :) I'm using the ZMQStream in the broker. Made the whole thing a lot easier. I wanted to have a different set of examples using the more advanced features of pyzmq. Hope this answers your question. |
Yes, I have no intention of removing the existing (bad) API in the foreseeable future for this reason. But I don't want the new API to appear as if it's sugar wrapped around the old API. Docs, examples, etc. should never mention the old API, and it should never occur to new users to use it. That's why I don't like the idea of writing docs with An alternative would be to continue to use the same on_recv name, but switch to the new behavior with a |
Hi! Please try to see this from the point of a user. See, on IRC there are still questions on where the device programs are. The only way to get a migration going is to provide the alternative and explain what the benefits are. You can't -- and shouldn't -- force it. This builds opposition and scares away people. If you write the reason for having the new methods into the docs, then I assume every Cheers |
Fair point about about the explanation, I will certainly do that. Though the old methods should still not be mentioned in any place other than that explanation of why the new names are not what they should be. I don't want to pretend that these new methods mean there are two ways of doing things. These are the exact same methods with a single extra argument that should have always been there in the first place, and the old methods only exist for backwards compatibility (which is important). |
I think I'm just going to have to give up on my desire to "fix" the API. Since it really can't be done in a backward-compatible way, I'm not sure it's useful. What should have always been the case is that on_recv callbacks are passed the stream itself. Since this wasn't done, there is simply no path forward that fixes this mistake that doesn't break APIs. Adding a second Users who want on_recv to behave as it always should have can simply get used to the lambda+closure trick:
|
I agree that we should have passed the stream from the start, but give I am a little more willing to add the new functions under some Go ahead and make the final decision on this one, but I am +1 on On Tue, Feb 7, 2012 at 2:59 PM, Min RK
Brian E. Granger |
Hi! ellisonbg is right (imho), both +1 (the credits and the new function). Cheers |
Currently, the on_recv/on_send system only passes the message to the callback, but they should really pass both the stream and the message. This is the way the czmq reactor behaves, and it makes it easier to use the same callback with multiple streams.
The only tricky thing here is how to add this in a sensible way that does not break current apps that only expect the one argument.
For now, this behavior can be emulated with closures and intermediary functions:
But this is suboptimal.
The text was updated successfully, but these errors were encountered: