From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Noah Friedman Newsgroups: gmane.emacs.devel Subject: sit-for and idle timers Date: Fri, 11 Aug 2006 12:48:41 -0700 (PDT) Message-ID: <20060811124841.840381.FMU5696@piglet.prv.splode.com> Reply-To: Noah Friedman NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1155325755 28938 80.91.229.2 (11 Aug 2006 19:49:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 11 Aug 2006 19:49:15 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 11 21:49:11 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GBd0F-0003B9-33 for ged-emacs-devel@m.gmane.org; Fri, 11 Aug 2006 21:49:07 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GBd0E-0006V6-3F for ged-emacs-devel@m.gmane.org; Fri, 11 Aug 2006 15:49:06 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GBd03-0006Ta-AD for emacs-devel@gnu.org; Fri, 11 Aug 2006 15:48:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GBd00-0006QQ-IB for emacs-devel@gnu.org; Fri, 11 Aug 2006 15:48:55 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GBd00-0006QN-DO for emacs-devel@gnu.org; Fri, 11 Aug 2006 15:48:52 -0400 Original-Received: from [209.237.242.10] (helo=nutty-waffle-cone.splode.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.52) id 1GBd5B-0002H8-Rt for emacs-devel@gnu.org; Fri, 11 Aug 2006 15:54:14 -0400 Original-Received: from piglet.prv.splode.com ([67.125.18.14]) by nutty-waffle-cone.splode.com (8.13.1/8.13.1) with ESMTP id k7BJmfX1016936; Fri, 11 Aug 2006 12:48:42 -0700 X-DomainKeys: Sendmail DomainKeys Filter v0.2.2 nutty-waffle-cone.splode.com k7BJmfX1016936 Original-To: emacs-devel@gnu.org, cyd@stupidchicken.com X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:58300 Archived-At: The change to sit-for of 2006-07-26 ("Use new SECONDS arg of read-event instead of a timer") seems to cause problems with idle-timers which call sit-for. The problem is that read-event's call tree ultimately results in calling keyboard.c:read_char, which calls timer_start_idle. This resets the activation time for all the current idle timer events, which means that any function on an idle timer which calls sit-for is now getting scheduled to be run recursively if another interval of the appropriate length ensues. I imagine this can continue until max-lisp-eval-depth is reached. Here's a small test case which demonstrates the problem: (defvar itimer-test-wait 0.5) (defvar itimer-test-depth 0) (defun itimer-test () (setq itimer-test-depth (1+ itimer-test-depth)) (unwind-protect (let ((flag nil)) (while (sit-for itimer-test-wait) (setq flag (not flag)) (message "itimer-test-depth: %-3d%s" itimer-test-depth (if flag " (blink)" "")))) (setq itimer-test-depth (1- itimer-test-depth)) (message "itimer-test-depth: %d" itimer-test-depth))) (run-with-idle-timer 0.25 t 'itimer-test) In the pre-7/26 implementation, this timer should never print a depth greater than 1, and the "(blink)" text should blink on and off with a regular rhythm. In the post-7/26 implementation, itimer-test-depth increments indefinitely until an event is read. One solution to this problem is to bind timer-idle-list to nil while calling read-event. I tested this trivially with a small defadvice: (defadvice read-event (around idlefrob activate) (let ((timer-idle-list nil)) ad-do-it)) I'm not sure if this (binding the variable in sit-for that is, not the use of defadvice as a temporary kludge) is the correct solution since it will preempt the activation of other idle timers. But it's simple. The less simple solution is probably for sit-for to go back to using a timer itself. Thoughts?