Opened 11 months ago

Last modified 10 months ago

#9279 enhancement new

Twisted docs should have a doc explaining interop with asyncio

Reported by: Craig Rodrigues Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description (last modified by Craig Rodrigues)

In 9204, Alex mentioned:

I was interested in learning more about twisted/asyncio 
interoperability, and I had no idea where to click. I _assume_ 
it's somewhere in "Twisted Core", but even clicking on that
yielded nothing fruitful.

We need a proper document explaining interop with asyncio.

Change History (2)

comment:1 Changed 11 months ago by Craig Rodrigues

There is some documentation for using asyncio here:

https://twistedmatrix.com/documents/current/core/howto/defer-intro.html#coroutines-with-async-await

Klein now has a good example for using async/await keywords:

https://klein.readthedocs.io/en/latest/examples/await.html

The main asyncioreactor is documented at https://twistedmatrix.com/documents/current/api/twisted.internet.asyncioreactor.html

The simplest example is:

import asyncio
from twisted.internet import asyncioreactor, reactor
loop = asyncio.get_event_loop()

asyncioreactor.install(eventloop=loop)
reactor.run()

Here is a fancy example which uses Python asyncio, uvloop, and twisted.web combined:

https://gist.github.com/ldjebran/4febf298232a6fd86871df25d4dc00dd

comment:2 Changed 10 months ago by Craig Rodrigues

Description: modified (diff)
Note: See TracTickets for help on using tickets.