From: "João Távora" <joaotavora@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: A question regarding sit-for (and while-no-input)
Date: Thu, 04 Oct 2018 17:33:03 +0100 [thread overview]
Message-ID: <jjbtvm1pt8g.fsf@gmail.com> (raw)
In-Reply-To: <jwvr2i6st8z.fsf-monnier+gmane.emacs.devel@gnu.org> (Stefan Monnier's message of "Thu, 06 Sep 2018 08:33:32 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> 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
next prev parent reply other threads:[~2018-10-04 16:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-06 11:29 A question regarding sit-for (and while-no-input) João Távora
2018-09-06 11:59 ` João Távora
2018-09-06 12:33 ` Stefan Monnier
2018-10-04 16:33 ` João Távora [this message]
2018-10-05 12:36 ` Stefan Monnier
2018-10-06 10:35 ` João Távora
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jjbtvm1pt8g.fsf@gmail.com \
--to=joaotavora@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).