[Twisted-Python] How to combine two eventloops into one?

Glyph glyph at twistedmatrix.com
Tue May 22 23:50:09 MDT 2018



> On May 21, 2018, at 2:22 AM, Shiyao MA <i at introo.me> wrote:
> 
> Hi,
> 
> We are developing a network-facing GUI software.
> 
> One team member builds the GUI software, which is based on PyQT and
> the eventloop is qt5reactor.
> 
> Another team member writes the network functions, which is based on
> the https://github.com/bmuller/kademlia repo.  Again, our code is
> built upon twisted, but to account for the kademila package, we switch
> the underlying event loop to asyncio.
> 
> Now the problem comes as to how to integrate the GUI (qt5reactor) with
> the network(aysncio) eventloop?
> 
> Possible to build a meta eventloop that combines qt5reactor and asyncio?
> Otherwise, any better approach?

It's definitely possible.

Right now, the integration we've implemented puts asyncio "on the bottom" and twisted "on top"; in the sense that twisted.internet.asyncioreactor implements the Twisted reactor API in terms of the native asyncio event loop.

It would also be possible to implement the asyncio event loop interface, as specified in https://www.python.org/dev/peps/pep-3156/#event-loop-interface-specification <https://www.python.org/dev/peps/pep-3156/#event-loop-interface-specification>, in terms of the Twisted reactor interfaces.  Many of the methods are quite similar.  If we had such a wrapper in Twisted already, you could wrap your qt5reactor instance in a ReactorLoop() and install that into asyncio using an event loop policy.

I hope someone will contribute this ;-).

-g
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20180522/665bc144/attachment-0002.html>


More information about the Twisted-Python mailing list