Domanda

I am using the autobahn websocket with the pubsub.

I have a service that gets data and collects it and puts it in a topic in Redis

I then want to listen for new messages and then publish to a topic with the autobahn pubsub. It works fine when the function exits, but when I put it in a for loop (constantly listen for new redis messages) It does not publish anything

I think its because this is blocking the reactor to actually publish the data. Iv tried looking into deferToThread but that doesnt work.

I was wondering does anyone know how i could basically go about publishing data in a while loop to the autobahn topics.

Thanks

È stato utile?

Soluzione

You can connect to Redis in a blocking loop on a background thread, and deferToThread is one way to do that in Twisted, but only half of the story: the other half is using callFromThread to call into Autobahn's publish/dispatch running on the main thread.

You can read more here: http://twistedmatrix.com/documents/13.2.0/core/howto/threading.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top