On Thu, 13 Sep 2001, Dunford, Martin wrote:

> Hi everybody
>
>   I am building a GUI for a scaling application that every
> few milliseconds outputs four or five lines of status information
> on how each Client is proceeding etc.etc.
>
>   I've got the layout, buttons, menus etc. all laid out as I
> wish. My only problem is how to periodically have the
> app. write to the console window (a GtkText and GtkScrollbar
> in a GtkVbox).
>
>   In trying to figure this out (I am a GUI novice) I came up with
> simple little app below. All it wants to do is write to a console
> periodically and see what it writes appear correctly..However
> I have had mixed and somewhat bewildring results (I shudder
> to think of having to deal with this in C++ and the burden of
> increased complexity and endless recompilations)
>
>   Basically it forks a child process that tries to write to the
> console while the parent spins on GTK mainloop() or something
> close to it....Here's what happened for various parent/child
> scenarios (the complete app appears at the end of my mail)

This code looks very evil :).  In a GTK program, if you fork, the child
process can't make any gtk calls, and must use _exit() rather than exit()
(so as not to hang up the X connection).  Manipulating widgets in the
child process is really asking for trouble.

Both the parent and child processes are sharing the X connection, without
any locking or synchronisation, which is asking for trouble.  If you need
to use multiple processes, you should create some pipes (os.pipe) before
forking.  The child can write into the pipe, and the parent can read from
the pipe.  You can use gtk.input_add() to set a callback that will be
called everytime there is data to be read from the pipe.

James.

-- 
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/


_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to