views:

20

answers:

1

Hi there.
I am trying to write a simple TCPServer and a client with Twisted python. Everything is working well; but, there is a way to defer some tasks to different threads? For example, is it possible to do:

  • take an input from the user until \n, then send the data to the server;
  • accept all the incoming messages from the server and write to the screen;

simultaneously?
Which are best practices?

Thank you for your help.
—Donovan

+1  A: 

Threads are one implementation strategy for doing these things simultaneously. Twisted generally goes with another strategy - non-blocking I/O and an event multiplexer (eg select(2)).

If you want to handle input from stdin while you have a TCPServer running, all that means is that you want to use Twisted's APIs for reading from stdin, just like you're using Twisted's APIs for handling network connections.

See twisted.internet.stdio.StandardIO for that.

Jean-Paul Calderone