1

I want to be able to reading data to send over a websocket from the standard Python world (ideally an iterator over standard input), and send it to a websocket that has been created in Tornado

The standard Tornado examples all have a "main" equivalent that calls something similar to "tornado.ioloop.IOLoop.instance().start()", which I think means it isn't possible to easily run standard Python code in parallel

The question below helps a little with the confusion of how you write to a Tornado websocket from somewhere other than the websocket handler itself (both initial examples I found only referenced the websocket write_message from within the handler):

How do I send a websocket message in Tornado at will?

However, this example is still triggering the Websocket write from within an event that happens in the "Tornado world" (an HTTP get)

There are other examples out there for how to access standard input from a Python "asyncio" environment here:

python asyncio how to read StdIn and write to StdOut?

And (I think) how to run a background task in parallel with Tornado as a Gist here:

https://gist.github.com/marksilvis/ea1142680db66e2bb9b2a29e57306d76

(note there are a few bugs in that example that means it doesn't run)

But these are all using different frameworks, and converting so that they could be combined together seems to be very complex.

Is there any guidance out there for how to use a Tornado "yield" or alternative "async" method to be able to read from a file while handling websocket connections?

Michael Firth
  • 482
  • 5
  • 11
  • I'm not quite clear on what triggers the websocket write - data on standard input? Also, what version of Tornado/Python are you using? – Nathaniel Verhaaren Mar 06 '21 at 16:09
  • @NathanielVerhaaren - Yes, I was wanting to read data from standard input and write it to any connected Websocket client. I was using Tornado 4.4.3 and Python 3.5.3. I ended up giving up on the Python approach and doing what I needed in C++ with WebsocketPP, which ended up being much easier for my task (given I am more of a C++ developer than a Python one) – Michael Firth Mar 12 '21 at 10:41

0 Answers0