简体   繁体   English

如何向龙卷风添加自定义事件

[英]How to add custom events to tornado

I have a tornado application that will serve data via websocket. 我有一个龙卷风应用程序,它将通过websocket提供数据。 I have a separate blocking thread which is reading input from another application and pushing an object into a Queue and another thread which has a blocking listener to that Queue. 我有一个单独的阻塞线程,该线程正在从另一个应用程序读取输入并将一个对象推入一个队列,而另一个线程对该线程有阻塞侦听器。

What I would like is for the reader thread to somehow send a message to tornado whenever it sees a new item in the Queue and then tornado can relay that via websocket to listening clients. 我想要的是让读者线程在队列中看到新项目时以某种方式将消息发送给龙卷风,然后龙卷风可以通过websocket将其中继给正在监听的客户端。

The only way I can think to do this is to have a websocket client in the reader thread and push the information to tornado via websocket. 我能想到的唯一方法是在阅读器线程中拥有一个websocket客户端,然后通过websocket将信息推送到龙卷风。 However it seems that I should be able to do this without using websocket and somehow have tornado listen for non websocket async events and then call a callback. 但是,似乎我应该能够在不使用websocket的情况下执行此操作,并且以某种方式使龙卷风侦听非websocket异步事件,然后调用回调。

But I can't find anything describing how to do this. 但我找不到任何描述方法。

If I'm understanding your question correctly, all you need to do is call IOLoop.add_callback from the thread that is reading from the queue. 如果我正确理解了您的问题,那么您需要做的就是从正在从队列中读取的线程中调用IOLoop.add_callback This will run your callback in the IOLoop's thread so you can write your message out on the client websocket connections. 这将在IOLoop的线程中运行回调,因此您可以在客户端Websocket连接上写出消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM