4 ms·
Cool! I actually starred your project last year. Never really got around to looking under the hood though. How do you handle the "multiple destinations" part? I
by reubano 10y ago
Cool! I actually starred your project last year. Never really got around to looking under the hood though. How do you handle the "multiple destinations" part? In python you can do it with a coroutines [1, 2] implementation (push based). I avoided that, since it coroutines have their own form of callback hell, and decided to implement a generator api (pull based) [3, 4].
But since generators can only be "pulled" into one destination, you have to copy a stream (subsequently converting it into a list) if you want more than one destination [5]. This works fine if the data can fit in memory, but if it can't then you're out of luck!
[1] http://www.dabeaz.com/coroutines/copipe.py http://www.dabeaz.com/coroutines/copipe.py
[2] http://www.dabeaz.com/coroutines/ http://www.dabeaz.com/coroutines/
[3] http://www.dabeaz.com/generators/retuple.py http://www.dabeaz.com/generators/retuple.py
[4] http://www.dabeaz.com/generators http://www.dabeaz.com/generators
[5] https://github.com/nerevu/riko/blob/master/riko/modules/split.py#L15-L18 https://github.com/nerevu/riko/blob/master/riko/modules/spli...
- olviko 10y agoCan’t really remember, sorry, that code was built for processing RSS feeds and data size was never an issue. I will take a look when get some free time… But, I see what you mean. I had to deal with similar issues in commercial projects and the "pull" model (generators in Python ~ "yield return" in C#) almost never a good idea, especially when you have to have concurrent consumers. While callbacks are hard to combine, in C# it can be nicely abstracted with “async/await”, not sure how it is handled in Python, I stopped using it around 2.5
- greenshackle 10y agoPython 3.5 introduced the async/await syntax, I don't do C# but at a glance it's the same. I've been working on a similar project and I've also found the push model easier.
- reubano 10y agoCare to share your code? I'd like to see a proper push implementation.
- infinite8s 10y agoAnother benefit of the push model is that back pressure becomes much easier to implement.
- reubano 10y agoAny code to share? I've yet to see how to properly do push.