rickardp / splitstream

Continuous object splitter for C and Python
Apache License 2.0
44 stars 9 forks source link

Async support in Python #15

Open pskopnik opened 1 year ago

pskopnik commented 1 year ago

Async support for the splitstream Python library would be much appreciated. Python I/O applications are increasingly moving to rely on the async/await semantics and so far there is no way of using splitstream for reading JSON objects in these cases.

Specifically, async support for me means a new variant of splitfile, which:

There are two obvious ways of providing async support:

To me, the second approach sounds more interesting and would match exactly what the current splitstream library does. It could also reuse most of the existing code (after some refactoring) boiling down to a more complex state machine for the generator.

I'm available to provide an initial implementation. Although I've not yet worked with the async protocols in C extensions, I've looked at the underlying concepts and am confident to get something working (open questions: how to implement send()/throw()/close() for the iterator representing the awaitable :thinking: ).

rickardp commented 1 year ago

I agree that the second approach would be more appropriate. Note that to be performant, file I/o is offloaded to the C code rather than calling the reader to get the bytes. A lot of string copying is avoided that way, this makes a huge difference. I wonder if this also means async file I/o would be needed for this to be useful in practice? As as it is usually not for file I/o you’re looking at async, I suspect what would really be needed is sockets.

Do you have a concrete use case for this? Maybe it would help starting to look from that end?