From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joe Wells Newsgroups: gmane.emacs.bugs Subject: bug#300: strange interaction of periodic timers and suspending Emacs 22.1 Date: Thu, 22 May 2008 20:52:13 +0100 Message-ID: <86tzgq3ymq.fsf@macs.hw.ac.uk> Reply-To: Joe Wells , 300@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1211490987 19617 80.91.229.12 (22 May 2008 21:16:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 May 2008 21:16:27 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 22 23:17:04 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JzI9U-0006aB-Tz for geb-bug-gnu-emacs@m.gmane.org; Thu, 22 May 2008 23:16:45 +0200 Original-Received: from localhost ([127.0.0.1]:47415 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JzI8k-0003jq-Cg for geb-bug-gnu-emacs@m.gmane.org; Thu, 22 May 2008 17:15:58 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JzH8c-00070O-9W for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 16:11:46 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JzH8b-000705-BF for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 16:11:45 -0400 Original-Received: from [199.232.76.173] (port=44972 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JzH8b-000702-8q for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 16:11:45 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:52065) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JzH8a-0006ir-Nh for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 16:11:45 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m4MKBgfH016890; Thu, 22 May 2008 13:11:42 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m4MK037X012776; Thu, 22 May 2008 13:00:03 -0700 X-Loop: don@donarmstrong.com Resent-From: Joe Wells Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Thu, 22 May 2008 20:00:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 300 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.121148595811468 (code B ref -1); Thu, 22 May 2008 20:00:03 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 22 May 2008 19:52:38 +0000 Original-Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m4MJqSBV011459 for ; Thu, 22 May 2008 12:52:30 -0700 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JzGpw-00028b-CK for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 15:52:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JzGpq-000229-Ok for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 15:52:27 -0400 Original-Received: from [199.232.76.173] (port=43592 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JzGpq-00021p-Bn for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 15:52:22 -0400 Original-Received: from mail-r.hw.ac.uk ([137.195.101.215]:59168) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JzGpp-0001jJ-Bw for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 15:52:21 -0400 Original-Received: from izanami.macs.hw.ac.uk ([137.195.13.6]) by mail-r.hw.ac.uk with esmtp (Exim 4.54) id 1JzGpc-0007BX-3Y for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 20:52:08 +0100 Original-Received: from lxultra1.macs.hw.ac.uk ([137.195.27.173]:46602 helo=127.0.0.1) by izanami.macs.hw.ac.uk with smtp (Exim 4.51) id 1JzGpb-0006c3-Su for bug-gnu-emacs@gnu.org; Thu, 22 May 2008 20:52:08 +0100 Original-Received: (nullmailer pid 21720 invoked by uid 1001); Thu, 22 May 2008 19:52:13 -0000 User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-HW-MailScanner-Information: Please contact the HW Helpdesk for more information X-HW-MailScanner: Found to be clean X-HW-MailScanner-SpamCheck: not spam, SpamAssassin (score=-4.399, required 5, autolearn=not spam, ALL_TRUSTED -1.80, BAYES_00 -2.60) X-HW-MailScanner-From: jbw@macs.hw.ac.uk X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Thu, 22 May 2008 16:11:45 -0400 X-Mailman-Approved-At: Thu, 22 May 2008 17:15:53 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:18099 Archived-At: Dear GNU Emacs gurus, When Emacs 22.1 resumes from being suspended, it will execute a periodic timer once for each time it would have executed it if Emacs had never been suspended. The same thing happens when the entire computer is suspended (i.e., hibernation (suspend to disk) or sleep (suspend to RAM)). While it is conceivable that some uses of timers might prefer the current behavior, in the vast majority of cases a timer does a recurrent task and there is no benefit from repeating the timer zillions of times in a row. In fact, this can cause Emacs to freeze for a long time when resuming due to processing periodic timers if the timers do significant work. It would be better if it was possible to get a periodic timer to execute at most once for a period of time during which Emacs (or the entire computer) was suspended. Depending on your point of view, this is either a bug report (my viewpoint) or a feature request. To reproduce the behavior, start Emacs with this command: emacs -nw -Q (You must be using a shell where the command "fg %1" will resume this Emacs if it is suspended. If not, adjust the reproduction code below to use the correct command to resume Emacs.) Then evaluate these 3 sexps: (defun foo-timer (x) (or (eq x 'xyzzy) (error "impossible")) (setq foo-counter (1+ foo-counter)) ;;(message "foo-counter: %d" foo-counter) ;;(setq bar-counter foo-counter) (save-excursion (set-buffer foo-buffer) (goto-char (point-max)) (insert (format " %d" foo-counter)))) (defun foo-test () (interactive) (and (boundp 'foo-timer) (timerp foo-timer) (cancel-timer foo-timer)) (setq foo-counter 0) (setq foo-buffer-name "*foo-buffer*") (kill-buffer (get-buffer-create foo-buffer-name)) (setq foo-buffer (get-buffer-create foo-buffer-name)) ;; Once per second, starting now. (setq foo-timer (run-at-time t 1 #'foo-timer 'xyzzy)) (switch-to-buffer foo-buffer) (sit-for 5) (goto-char (point-max)) (insert " suspending") ;; extra BUG: In violation of its documentation, suspend-emacs ;; will add a newline or return character to the string it is ;; asked to stuff as terminal input. (suspend-emacs "sleep 10; fg %1") (goto-char (point-max)) (insert " resuming") ;; possible extra BUG: It is strange that the (sit-for 0) needs to ;; be repeated to get all the events. The first (sit-for 0) ;; generally only gets 3 events. (dotimes (x 20) (sit-for 0)) (goto-char (point-max)) (insert " canceling") (cancel-timer foo-timer) (buffer-string)) (foo-test) After this finishes, the contents of the *foo-buffer* buffer will be (roughly) this string: " 1 2 3 4 5 suspending resuming 6 7 8 9 10 11 12 13 14 15 canceling" The count can sometimes reach 6 before suspending and 16 before canceling. Instead of the current Emacs behavior, it would be very desirable to be able to have periodic timers whose behavior would leave the contents of the *foo-buffer* buffer as this string: " 1 2 3 4 5 suspending resuming 6 canceling" It is very undesirable to have a periodic timer repeated zillions of times upon resuming Emacs. Note that the same problem happens when the entire computer is suspended and resumed. In addition to wanting to see this problem fixed, I would also be interested to hear of a reliable way to work around it. I hope this report is helpful. -- Joe Wells ====================================================================== In GNU Emacs 22.1.1 (i686-pc-linux-gnu, GTK+ Version 2.8.20) of 2007-06-27 on artemis configured using `configure '--prefix=/home/jbw/local2' '--enable-debug' '--disable-nls' '--with-x-toolkit=gtk' 'CFLAGS=-O0 -g3 -ggdb'' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: en_US.UTF-8 value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: jbw value of $LANG: nil locale-coding-system: utf-8 default-enable-multibyte-characters: t Major mode: Fundamental Minor modes in effect: encoded-kbd-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t unify-8859-on-encoding-mode: t utf-translate-cjk-mode: t auto-compression-mode: t line-number-mode: t -- Heriot-Watt University is a Scottish charity registered under charity number SC000278.