-
Notifications
You must be signed in to change notification settings - Fork 51
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
Expose push / sax-like interface #22
Comments
@Alexander255 I have been working on a set of changes implementing this, but they are not fully fleshed, so I haven't made them available for testing publicly yet. The main idea is to decouple I/O from the parsing logic, handling only buffers of data as input, and have these new methods be the building-blocks of the rest of the library. I am doing this using coroutines (as in "generators with All of this is working fine for all backends with no drop in performance, with the sole exception of the C backend, which I haven't finished porting yet (but it's about 50% done). Apart from that I also have a first version of I expect all these changes will become ijson 3.0, and hopefully t won't take much more longer to finish. |
@rtobar: That sounds great! (The interface in my example was just an illustration on the general concept to get the general idea across, but what you proposed is much better thought out anyways.) |
@Alexander255 the very first version on this work is finally available. If you could, would you mind trying out the code in the new |
New interfaces now exposed on the {{master}} branch. Have a look at the README file to learn more about this. There is a release candidate up in PyPI too (3.0rc1) with these changes, so people can go ahead and test them and provide feedback before a final 3.0 release is done. |
Sorry about only looking at this now. While I haven't used it yet, the offered push interface will definitely work for our needs, so thank you about that! Some feedback: It looks like the stream reading code of the data = await self.f.read(self.buf_size) in utils35.py to this: if hasattr(self.f, "receive_some"): # Trio's ReceiveStream
data = await self.f.receive_some(self.buf_size)
else: # AsyncIO's StreamReader + Trio's Async Files + CurIO's SocketStream + CurIO's FileStream
data = await self.f.read(self.buf_size) I know it's dumb to have exactly one outlier in that list, but it's just the way things are right now… The difference in interface does make some sense when you view it purely from the perspective of what the interface represents within the trio system (some random thing that gives you data) – from the PoV of somebody trying to be ecosystem agnostic it's of course a totally unnecessary complication, but when you (as they did/do) only have trio consumers in mind I think their decision was by itself quite understandable. |
@Alexander255: let me ask the inverse question: would it be possible for you to alter your trio objects so they have a f = the_trio_file_type()
f.read = f.receive_some
async for object in ijson.items_async(f, ''):
pass If it's not possible to add members to trio objects, a thin wrapper would also do. On the other hand, I'm the first to admit that I'm not very well versed on the |
@rtobar: Obviously I can wrapper these up, but it's just not the same to having it just work without any further ado. I don't blame you for that decision though, I'd probably done the same in your stead. 🙂 Let me just request some tiny amendment however: Could you rename the PS: Regarding AIO frameworks, I think it's very unlikely that we are going to see more of them anytime soon. |
@Alexander255 the new name is a very good suggestion, and easy to get done. I'll do it for the next rc. Thanks for the clarification on frameworks too, one day I might need to delve deeper into that world. |
Mmmm... actually thinking about it again I'm not sure anymore... the |
@rtobar: All the AIO frameworks use |
@Alexander255 yes, I understand that while there are multiple frameworks/APIs all of them share the same underlying mechanism for declaring coroutines ( The point I was trying to make was different: On top of that, in both |
Dealing with asyncio streams I was wondering how realistic it would be to make this awesome library into something that accepts a push pattern.
Thinking about something like:
The current system only supports blocking I/O and there is no way to emulate the above without using threads and pipes/queues unfortunately.
The text was updated successfully, but these errors were encountered: