This is the mail archive of the guile-gtk@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: timer and progress-bar-update related question


On Mon, 1 Oct 2001, David Pirotte wrote:

> Hello,
> 
> i am trying to trigger a timer, while the application should see if the computer
> is connected to a network and can ping a specific host
> 
> i have defined a dialog, modal, that contains a progress-bar, user information
> ... (see code below).
> 
> there is no bug, but the timer seems 'to be activated', but nothing gets displayed
> on the screen (no progress bar update) until the call to (gping "picpic") returns:
> 
> how can i force ou flush the progress-bar-update so that the user sees something
> while (gping "picpic") is performed?

In order to keep a GUI program responsive, you can never do any operations
that block or wait - which includes the call to wait(2) inside of
system(3).  (The libguile (system cmd) procedure simply calls the standard
C library system routine.  If you do block, the processing of all events,
including X input and gtk's timers grinds to a halt.


There are several ways to get around this, but the most straightforward is
probably to build your own equivalent of system(3), but instead of calling
wait(2), set up a handler for the SIGCHLD signal.  When SIGCHLD is
recieved, call (waitpid WAIT_ANY WNOHANG) to see which of possibly many
child processes is has completed, and what its status was.  Meanwhile,
everything else continues to run.

The guile reference manual suggests that this can all be done easily
entirely within guile - but I haven't tried it myself.  It looks like some
useful pieces can be scavanged from procedure
(open-process) in ice-9/popen.scm.

Another way to do this might include guile threads

A third way would be to build a ping-equivalent yourself using a socket on
which you can then do (gtk-input-add) to get your guile code called when
ping-replies arrives on the socket.

It would be nice to gather a list of all of the libguile procedures that
should be avoided in guile-gtk programming.  A start:

	(system)
	(wait)
	(waitpid ) ; without WNOHANG flag
	(sleep) ; use gtk timers
	(select) ; use gtk-input-add



--
Steve Tell  tell@telltronics.org 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]