gtk-timeout-add function stalling

Paul Emsley <[email protected]> Sun, 10 Jan 2010 14:52:45 +0000
Newsgroups gmane.lisp.guile.gtk
Message-ID <[email protected]>
Hi,

I am trying to update a progress bar that is downloading a file using 
libcurl in a thread.  I am doing that by adding a timeout function that 
every fraction of a second or so queries the status of the download 
(curl-progress-info).  However, after a number of rounds (somewhere 
between 100 or 250) the timeout function seems to hang - even partway 
through writing a debugging text. (The thread downloading the file 
continues.)  Why does the timeout function stalling?

 [with guile 1.8.7 embedded]

Thanks,

Paul.


------

Here's a fragment:


     ... setup the dialog....

     (gtk-signal-connect ok-button "clicked"
          (lambda ()
               (call-with-new-thread
                 (lambda ()
                   (if (not (run-download-binary-curl revision 
version-string))
                     (set! pending-install-in-place 'fail)))
                 updates-error-handler)))


     ... more setting up ...

    (gtk-timeout-add
       500 (lambda ()
         (cond
          ((eq? pending-install-in-place 'fail)
           (gtk-widget-destroy window)
           (info-dialog "Failure to download and install binary")
           #f)
          (else
           (update-progress-bar progress-bar)
           #t))))

  ;;
  (define update-progress-bar
    (let ((count 0)
          (active-count 0))
    (lambda (progress-bar)
      (set! count (+ count 1))
      (if (string? file-name-for-progress-bar)
        (let ((curl-info (curl-progress-info file-name-for-progress-bar)))
          (set! active-count (+ active-count 1))
          (if curl-info
            (let ((v1 (assoc 'content-length-download curl-info))
                  (v2 (assoc 'size-download           curl-info)))
              (if (list v1)
                 (if (list v2)
                    (let ((f (/ (cdr v2) (cdr v1))))
                        (format #t "count ~s, active-count ~s, f: ~s~%" 
count active-count f)
                        (gtk-progress-bar-update progress-bar f)))))))))))