Take the 2-minute tour ×

I am running a twisted process which needs to interact with the user, without blocking. The idea is that the user will be asked to input some data, and once a complete line has been entered, the program will process it, eventually triggering events. During the period that the user is entering data, the reactor must keep on running normally.

Is there any support in twisted for that?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can read from standard input using twisted.internet.stdio. See stdiodemo.py and stdin.py at http://twistedmatrix.com/documents/current/core/examples/.

You can also use Gtk using twisted.internet.gtk2reactor. See the pbgtk2.py example at the same examples page.

You can also use other GUI toolkits, though Gtk is the most well supported.

share|improve this answer
Is it possible to use the input take by this receiver and feed it off to another protocol so it can be piped over the network? –  DeaconDesperado Jul 2 '12 at 19:48
Sure. Input is handled by a protocol, which is just a bunch of Python code you write in a class you define. Feeding it to another protocol is just another way of saying "calling a method on an object", which is a great thing to do, and Twisted won't prevent you from doing that. :) A hurdle a lot of people seem to struggle with is arranging their code so they have a reference to a good object to call that method on. However, there's also nothing special involved in doing that. eg, pass the object as an init argument or set it as an attribute later on. Nothing fancy required. –  Jean-Paul Calderone Jul 3 '12 at 12:39
Calderon What I'm struggling with is that I have a stdio protocol that takes the input... I assign the factory for the network protocol as the factory attribute inside the stdio protocol, and then try to call methods by name (on the cli) of the network protocol. I am sure I have misunderstood this example somehow: share11.appspot.com/1421 My code: github.com/DeaconDesperado/swfty-share/blob/master/client.py –  DeaconDesperado Jul 3 '12 at 13:42
I don't think this can be answered in the comments section of this question. Consider posting a new question. –  Jean-Paul Calderone Jul 3 '12 at 14:18
Sorry, i meant to post the link - I had one up stackoverflow.com/questions/11297032/… –  DeaconDesperado Jul 3 '12 at 14:21

Your Answer


