2

I am using twisted to distribute some information to several clients.

I have a consumer (implements IConsumer) with the write method overridden to write to all connected consumer clients.

I have a data source implemented as a generator.

Here is my main function

factory = TelemetryFactory()
one2many = ConsumerToManyClientConsumers()
# writes from the datalines generator to one2many
telem = TelemetryProducer(one2many, datalines)
factory.setSource(one2many)
reactor.listenTCP(1234, factory)
reactor.run()

How do I run the generator (or the TelemetryProducer) so that the it always runs no matter how many clients there are (0-10)?

Edit: Using reactor.callInThread(fn) seems to give the desired behaviour, except that CTRL+C doesn't properly exit the program. After CTRL+C, all connections are refused, but control is not yielded back to the shell.

2
  • What generator? What fn? Please see sscce.org Commented Feb 17, 2014 at 12:55
  • The generator is any generator. It produces data from some source. The function runs the generator and writes data into the one2many consumer, which in turn writes to connected clients. The code is not really relevant to the question though, perhaps including it was a mistake. Commented Feb 18, 2014 at 8:00

1 Answer 1

0

Try twisted.internet.task.cooperate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.