emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question regarding sit-for (and while-no-input)


From: João Távora
Subject: Re: A question regarding sit-for (and while-no-input)
Date: Thu, 04 Oct 2018 17:33:03 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (windows-nt)

Stefan Monnier <address@hidden> writes:

>> A quick followup to my question.  I did some more tests and it seems an
>> using unwind-protect fixes the issue.
>>
>>    (unwind-protect
>>      (while (sit-for 30))
>>     (setq cancelled t)
>>     ...)
>
> Ha, that's exactly what I was about to suggest.

Hi again Stefan & the gang,

After a month-long delay, I am back with another question around this
issue.

I recently changed the code to use while-no-input +
accept-process-output instead of sit-for, because the latter would
sometimes hang in combination with company, company-quickhelp, and C-g.
(but it's very difficult to reproduce).

Anyway everything was going fine until I noticed an unexpected slowdown.
I made a little timing macro.

  (defmacro joaot/time (&rest body)
    `(let ((start (current-time)))
       (prog1
           (progn ,@body)
         (let ((msg (format "Took %s seconds"
                            (format-time-string
                             "%S.%3N"
                             (time-subtract (current-time) start)))))
           (if current-prefix-arg
               (insert " ; " msg " and returned ")
             (message msg))))))

These are the results of pressing C-u C-x C-e SPC in quick succession
after each expression.

   (joaot/time
    (while-no-input
      (while t (accept-process-output nil 0.1)))) ; Took 00.201 seconds and 
returned t
    
   (joaot/time
    (while-no-input
      (while t (accept-process-output nil 30)))) ; Took 03.822 seconds and 
returned t 
    
   (joaot/time
    (while (sit-for 30))) ; Took 00.126 seconds and returned nil 
    
   (joaot/time
    (while (sit-for 0.1))) ; Took 00.126 seconds and returned nil

I've switched to the first alternative, since it seems to solve the
problem.  I can't explain the long delay on the second one.  Can
someone?

Thanks,
João














reply via email to

[Prev in Thread] Current Thread [Next in Thread]