Hello,

I have used coroutines in a non-blocking HTTP client module for some
time. I have now finally cleaned and documented the code enough for it
to be useful to other people (no official release on PyPI yet, but code
and documentation is available on
https://bitbucket.org/nikratio/python-dugong and
http://pythonhosted.org/dugong/).

I think it would be rather nice if I could make this module work with
asyncio as well, but without having to depend on it.

I looked over the asyncio documentation at
http://docs.python.org/3.4/library/asyncio.html, but somehow I can't
seem to find the right information.

Currently, the coroutines in my module run until they encounter an I/O
operation that would block. In this case, they yield a tuple that
contains a file descriptor and the type of I/O operation they would like
to perform. For example, to implement a blocking read function I would
do:

coroutine = conn._co_read(256) # Method from my module
try:
    while True:
        io_req = next(coroutine)
        assert io_req.mask == select.EPOLLIN
        select.select((io_req.fd,), (), (), 0)
except StopIteration as exc:
    buf = exc.value
    

Now, asyncio seems to support coroutines as well, but I can't find any
information about what my coroutine is expected to yield in order for it
to work with an asyncio event loop.

I suppose that information isn't that often needed, because you are
supposed to use e.g. asyncio.StreamReader, in which case you can just
use "yield from". However, this isn't really an option for code that is
supposed to *integrate* with asyncio rather than *depend* on it.


Is the type of objects that are yielded by coroutines considered an
implementation detail that I should not depend on, or is it just not
documented yet? In the former case: is there any other way for me to
make my module compatible?


Thanks,
-Nikolaus

-- 
Encrypted emails preferred.
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

             »Time flies like an arrow, fruit flies like a Banana.«

Reply via email to