streamz icon indicating copy to clipboard operation
streamz copied to clipboard

AnyIO implementation of asynchronous streams

Open thedrow opened this issue 4 years ago • 14 comments

Using streamz with an event loop such as trio is currently not possible since Tornado only supports AsyncIO if it is available.

If we had an implementation that uses AnyIO, we could use any event loop we'd desire including tornado.

thedrow avatar Mar 30 '20 11:03 thedrow

What would that entail?

CJ-Wright avatar Mar 30 '20 12:03 CJ-Wright

Also how would that interact with dask?

CJ-Wright avatar Mar 30 '20 12:03 CJ-Wright

Indeed, a dask client requires an event loop. It is possible to supply an event loop instance at client creation, and I don't know exactly what it required of that loop instance - probably anything asyncio compliant. However, dask's loop can also run in a separate thread, so maybe it is possible to have two loops going (which may get complicated when actually dealing with dask-streamz).

martindurant avatar Mar 30 '20 12:03 martindurant

It's possible but not necessary if you aren't using dask.

thedrow avatar Mar 30 '20 16:03 thedrow

Have you tried using the anyIO (or other) loop for dask too? That would be the favourite solution if it works. Otherwise, I think I do basically agree that streamz should work regardless, but in practice, it may be tricky to demarcate dask-free parts of the code.

martindurant avatar Mar 30 '20 16:03 martindurant

There is no AnyIO implementation for dask. There's an AsyncIO implementation and a Tornado implementation. I have never used dask so no on both accounts.

It might be possible to run dask with trio-asyncio but I haven't really checked.

I want to implement streamz on another framework.

thedrow avatar Mar 30 '20 18:03 thedrow

This framework should not tie itself to a specific event loop. What if the next best thing comes around and everybody wants to use it?

thedrow avatar Mar 30 '20 18:03 thedrow

True, but being able to use Dask is important too. If you can implement anyIO (or something else) for the non-Dask code without greatly complicating the code, we would consider it. Of course we would still prefer smooth interaction between streamz and Dask on any io-loop.

martindurant avatar Mar 30 '20 18:03 martindurant

If you'd like to integrate Dask with other event loops I suggest taking it upstream.

I took a look at the code. It is currently impossible since you are tightly coupled with the Tornado event loop.

thedrow avatar Mar 30 '20 18:03 thedrow

Would uvloop, which is asyncio compatible, be a solution for you?

martindurant avatar Mar 30 '20 18:03 martindurant

xref: https://github.com/python-trio/trio-asyncio/issues/22#issuecomment-586974857

dhirschfeld avatar Mar 31 '20 01:03 dhirschfeld

Would uvloop, which is asyncio compatible, be a solution for you?

No. I need trio support.

thedrow avatar Mar 31 '20 07:03 thedrow