2

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)
Sanjiv
  • 813
  • 6
  • 13
  • What library are you using for socket.io? In general, when doing any kind of io from a trio app, you need a library that's designed for async usage *and* designed to work with trio, like trio-websocket. – Nathaniel J. Smith Jun 22 '20 at 23:46
  • @NathanielJ.Smith I am using this library: https://python-socketio.readthedocs.io/en/latest/ – Sanjiv Jun 23 '20 at 06:11

1 Answers1

1

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)
nosklo
  • 217,122
  • 57
  • 293
  • 297
  • I am already using trio-asyncio but i am not receiving broadcasted event, i am able to emit event but emitted event from server not being recieved to python-socketio-asyncclient – Sanjiv Jul 06 '20 at 10:24