Problem in running Trio with Kivy and Socket.io

Viewed 234

Currently, I'm trying to run Kivy, Socket.io as coroutine of Trio. It seems that Kivy UI showing the blank screen and seem to be unresponsive. Earlier, Kivy was working with Trio, after socket.io added, it became unresponsive. Provided Sample code for the same.

async with trio.open_nursery() as nursery:
     nursery.start_soon(kivy_sample_app)
     nursery.start_soon(websocket_client.connect)
     nursery.start_soon(command_line.run)
1 Answers

At a first glance, python-socketio is an asyncio library. It is not trio-compatible, as it uses asyncio functions to do the stuff.

Unfortunately, you can't just use asyncio-written libraries in trio. Both are async python libraries, but they use a different incompatible event loop.

Your alternatives are:

  1. Use a trio-based socketio implementation:
    • find a trio-based socketio library - I'm not aware of any implementation.
    • port python-socketio over to trio or write a new implementation from scratch - you could use anyio here to make a library that is compatible with both trio and asyncio at the same time
  2. Use a compatibility layer:
    • run asyncio on top of trio (trio-asyncio)
    • run trio on top of asyncio (trio.lowlevel.start_guest_run)
Related