[pygtk] Socket listening
David Ripton
dripton at ripton.net
Fri May 8 00:20:35 WST 2009
On 2009.05.05 13:39:51 +0200, Maxime Ripard wrote:
> I am new to pyGTK, and I have few problems writing a GUI for an existing
> program.
>
> One of the purpose of the program is to set up BOOTP and TFTP servers,
> to allow a PXE boot. Both servers are in different threads than the
> program itself.
>
> If was formerly using a cli, and everything was going fine.
>
> I now want to use a GUI, so I decided to use pyGTK and Glade.
>
> All the behaviour of my program is wrapped in a class, instanciated by
> both interfaces, in the same way. But with the GUI, everything is fine,
> the servers are launched and listen properly, except that nothing seems
> to come to them.
>
> I have read somewhere that when you need to listen on sockets while
> running the event loop, you have to use gtk.input_add(), but what if the
> sockets aren't in the same thread ? Do I have to use it anyway ?
>
> Launching the cli using subprocess.Popen within the GUI handlers makes
> it work, but it is kind of dirty to me, and not really what I want ...
>
> Is there any solution ?
The combination of PyGTK and threads is problematic. It works if you
follow all the rules but not always cleanly / easily / portably.
I've been disappointed with io_add_watch and friends. The API seems to
include everything you need, but it doesn't always work cleanly / easily
/ portably.
When I need to combine PyGTK and non-trivial networking, I use Twisted.
The main loops integrate seamlessly (using gtk2reactor) and then I use
Twisted APIs for networking and scheduling and PyGTK's APIs for the GUI
and it all works. But of course that may be a much bigger change than
you want.
--
David Ripton dripton at ripton.net
More information about the pygtk
mailing list