[Twisted-Python] Wanting to use Twisted, but a dependency uses asyncio
Hey friends. I'm in a position that is probably increasingly common. I'm working on a project that has a dependency that uses asyncio (kademlia). However, I much prefer to use Twisted. What's are some best practices for this at the moment? -- Justin Myles Holmes justinholmes.com thisisthebus.com github.com/jMyles/
Twisted 17.5.0 has new code to interoperate between Python's asyncio and "async def": https://twistedmatrix.com/documents/current/core/howto/defer-intro.html#coro... One example of where this is used is in Klein, a web microframework built on top of Twisted: https://klein.readthedocs.io/en/latest/examples/await.html Also, over 93% of Twisted's tests pass on Python 3: https://www.slideshare.net/CraigRodrigues1/the-onward-journey-porting-twiste... So I think that it is quite possible to look at using Twisted in a project which is using Python asyncio. -- Craig On Sun, Aug 27, 2017 at 11:06 AM, Justin Myles Holmes < twotonespirit@gmail.com> wrote:
Hey friends.
I'm in a position that is probably increasingly common. I'm working on a project that has a dependency that uses asyncio (kademlia).
However, I much prefer to use Twisted.
What's are some best practices for this at the moment?
Sure, syntactically it seems pretty close to gravy. But I'm wondering about flow control: if a project like kademlia is using the ayncio event loop, is it still practical to use twisted? On Sun, Aug 27, 2017 at 11:35 AM, Craig Rodrigues <rodrigc@crodrigues.org> wrote:
Twisted 17.5.0 has new code to interoperate between Python's asyncio and "async def":
https://twistedmatrix.com/documents/current/core/howto/ defer-intro.html#coroutines-with-async-await
One example of where this is used is in Klein, a web microframework built on top of Twisted:
https://klein.readthedocs.io/en/latest/examples/await.html
Also, over 93% of Twisted's tests pass on Python 3:
https://www.slideshare.net/CraigRodrigues1/the-onward- journey-porting-twisted-to-python-3
So I think that it is quite possible to look at using Twisted in a project which is using Python asyncio.
-- Craig
On Sun, Aug 27, 2017 at 11:06 AM, Justin Myles Holmes < twotonespirit@gmail.com> wrote:
Hey friends.
I'm in a position that is probably increasingly common. I'm working on a project that has a dependency that uses asyncio (kademlia).
However, I much prefer to use Twisted.
What's are some best practices for this at the moment?
-- Justin Myles Holmes justinholmes.com thisisthebus.com github.com/jMyles/
You can use this class to interoperate with the Python asyncio reactor and Twisted: https://twistedmatrix.com/documents/current/api/twisted.internet.asyncioreac... So you can do something like: 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 -- Craig On Sun, Aug 27, 2017 at 11:36 AM, Justin Myles Holmes < twotonespirit@gmail.com> wrote:
Sure, syntactically it seems pretty close to gravy.
But I'm wondering about flow control: if a project like kademlia is using the ayncio event loop, is it still practical to use twisted?
On Sun, Aug 27, 2017 at 11:35 AM, Craig Rodrigues <rodrigc@crodrigues.org> wrote:
Twisted 17.5.0 has new code to interoperate between Python's asyncio and "async def":
https://twistedmatrix.com/documents/current/core/howto/defer -intro.html#coroutines-with-async-await
One example of where this is used is in Klein, a web microframework built on top of Twisted:
https://klein.readthedocs.io/en/latest/examples/await.html
Also, over 93% of Twisted's tests pass on Python 3:
https://www.slideshare.net/CraigRodrigues1/the-onward-journe y-porting-twisted-to-python-3
So I think that it is quite possible to look at using Twisted in a project which is using Python asyncio.
-- Craig
On Sun, Aug 27, 2017 at 11:06 AM, Justin Myles Holmes < twotonespirit@gmail.com> wrote:
Hey friends.
I'm in a position that is probably increasingly common. I'm working on a project that has a dependency that uses asyncio (kademlia).
However, I much prefer to use Twisted.
What's are some best practices for this at the moment?
-- Justin Myles Holmes justinholmes.com thisisthebus.com github.com/jMyles/
Why are you all so awesome? What is your nefarious intention? Are you trying to make other open source projects look bad or what? Thanks so much Craig. On Sun, Aug 27, 2017 at 12:35 PM, Craig Rodrigues <rodrigc@crodrigues.org> wrote:
You can use this class to interoperate with the Python asyncio reactor and Twisted:
https://twistedmatrix.com/documents/current/api/twisted. internet.asyncioreactor.html
So you can do something like:
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
-- Craig
On Sun, Aug 27, 2017 at 11:36 AM, Justin Myles Holmes < twotonespirit@gmail.com> wrote:
Sure, syntactically it seems pretty close to gravy.
But I'm wondering about flow control: if a project like kademlia is using the ayncio event loop, is it still practical to use twisted?
On Sun, Aug 27, 2017 at 11:35 AM, Craig Rodrigues <rodrigc@crodrigues.org
wrote:
Twisted 17.5.0 has new code to interoperate between Python's asyncio and "async def":
https://twistedmatrix.com/documents/current/core/howto/defer -intro.html#coroutines-with-async-await
One example of where this is used is in Klein, a web microframework built on top of Twisted:
https://klein.readthedocs.io/en/latest/examples/await.html
Also, over 93% of Twisted's tests pass on Python 3:
https://www.slideshare.net/CraigRodrigues1/the-onward-journe y-porting-twisted-to-python-3
So I think that it is quite possible to look at using Twisted in a project which is using Python asyncio.
-- Craig
On Sun, Aug 27, 2017 at 11:06 AM, Justin Myles Holmes < twotonespirit@gmail.com> wrote:
Hey friends.
I'm in a position that is probably increasingly common. I'm working on a project that has a dependency that uses asyncio (kademlia).
However, I much prefer to use Twisted.
What's are some best practices for this at the moment?
-- Justin Myles Holmes justinholmes.com thisisthebus.com github.com/jMyles/
-- Justin Myles Holmes justinholmes.com thisisthebus.com github.com/jMyles/
What is your nefarious intention?
http://twistedmatrix.com/trac/ticket/5000 <http://twistedmatrix.com/trac/ticket/5000> duh
participants (3)
-
Craig Rodrigues
-
Hynek Schlawack
-
Justin Myles Holmes