From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?iso-8859-1?Q?Jo=E3o_T=E1vora?= Newsgroups: gmane.emacs.devel Subject: Re: A question regarding sit-for (and while-no-input) Date: Thu, 04 Oct 2018 17:33:03 +0100 Message-ID: References: <87k1nyzwx5.fsf@gmail.com> <87ftymzvjv.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1538670751 15609 195.159.176.226 (4 Oct 2018 16:32:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 4 Oct 2018 16:32:31 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (windows-nt) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 04 18:32:27 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g86Y6-0003w4-Oc for ged-emacs-devel@m.gmane.org; Thu, 04 Oct 2018 18:32:26 +0200 Original-Received: from localhost ([::1]:56951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g86aD-0002UE-Ax for ged-emacs-devel@m.gmane.org; Thu, 04 Oct 2018 12:34:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g86Yu-0002Sw-S2 for emacs-devel@gnu.org; Thu, 04 Oct 2018 12:33:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g86Ys-00025t-6p for emacs-devel@gnu.org; Thu, 04 Oct 2018 12:33:16 -0400 Original-Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:37021) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g86Yp-00021N-CA for emacs-devel@gnu.org; Thu, 04 Oct 2018 12:33:11 -0400 Original-Received: by mail-wm1-x331.google.com with SMTP id 185-v6so9718707wmt.2 for ; Thu, 04 Oct 2018 09:33:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=n17fK0SxwkbC9+7Re/iLpPWPkHrm+qdaXC5pt58JfoI=; b=jwwx3qX+ReE7kXjEyRvOIwuAVxKmGQEI+prc4OCpBiogBsIixagDf2gx7Y5HwBPfA2 XCQlXzxUb2jqnDVYSJtrfMlTfB9te1EkHGrisfKwq7DWVP3JJXkRXEiesZfqeNizJ72J QzmXQusfdvLMzxx++ZUoaeK5Zc+v2w4+R5ZgDHozzrSmJ3bJy75crZblwpQNGLng1ECb NIR0vF1/2lmIqt0Qwywt2rYlR6fqJL1jYxCDZu879KpEsgWrPK45JU+i7+ViuLhRmton mBOWDQBSX26IWDxMWBh2ZcgnfmGQVVdJkBflFsQzDn1Bua5ujEJi+Vxyi3lSTUkslEYv K0vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=n17fK0SxwkbC9+7Re/iLpPWPkHrm+qdaXC5pt58JfoI=; b=O4ZkK4Nq0VD2pBylflhhIK6Vhxrq/BaRq4FVCRFH39R1IjALb9BspPci3GcVyWPYAj u7ejIJfZeMJoqypaaoAi5lm6+Gc1T0XhyNAbgcnjXiiVnNNJh2ACHYPj5eK7whzO3hrc Sh+hzbsq19jZOkSa7fJU/8k5iYTJutWYDW0ABUs90fEOQyiCh+/q1ttq9B+I03X1R9ff nuokiPtxAd8lbSxG4Fik2r99a4zebQ+GSfUqi0EJ/qDm9xlYVSdgmKLc9lAP2uukicpE avOp3axB2Gq2Ugy3BJ8azMHBeXtF5fbqrr/zwMJs0THZGyBxAL0LR5w8THOHa7zQ0Mb2 F25A== X-Gm-Message-State: ABuFfoiNb2/qX6sUOpodDW9iiwkqpLCd0CdwiLpa7QGu5GM4rv58FTak DWl6mvUwN0IA7rBcvrbkobwPog+U X-Google-Smtp-Source: ACcGV62RPpddFjqERFOn2IV4kVEQztWEkej1tHOlRja5lOqfaf3ZiQom+DfyqLrWXKiADeX6PeK4Mw== X-Received: by 2002:a1c:4182:: with SMTP id o124-v6mr5625155wma.101.1538670787569; Thu, 04 Oct 2018 09:33:07 -0700 (PDT) Original-Received: from GONDOMAR.yourcompany.com (mail1.siscog.pt. [89.115.233.242]) by smtp.gmail.com with ESMTPSA id 63-v6sm6899818wmj.39.2018.10.04.09.33.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Oct 2018 09:33:06 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Thu, 06 Sep 2018 08:33:32 -0400") X-Antivirus: AVG (VPS 181004-2, 04-10-2018), Outbound message X-Antivirus-Status: Clean X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::331 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:230215 Archived-At: Stefan Monnier 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 =20=20=20=20 (joaot/time (while-no-input (while t (accept-process-output nil 30)))) ; Took 03.822 seconds and = returned t=20 =20=20=20=20 (joaot/time (while (sit-for 30))) ; Took 00.126 seconds and returned nil=20 =20=20=20=20 (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=E3o