all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joe Wells <jbw@rzlab.ucr.edu>
To: bug-gnu-emacs@gnu.org
Subject: bug#300: strange interaction of periodic timers and suspending Emacs 22.1
Date: Thu, 22 May 2008 20:52:13 +0100	[thread overview]
Message-ID: <86tzgq3ymq.fsf@macs.hw.ac.uk> (raw)

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.








             reply	other threads:[~2008-05-22 19:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <jwvr6bk7arz.fsf-monnier+emacsbugreports@gnu.org>
2008-05-22 19:52 ` Joe Wells [this message]
2008-05-23 21:17   ` bug#300: strange interaction of periodic timers and suspending Emacs 22.1 Stefan Monnier
     [not found]   ` <mailman.12118.1211578329.18990.bug-gnu-emacs@gnu.org>
2008-05-29 11:50     ` Joe Wells
2008-05-30  3:10   ` bug#300: marked as done (strange interaction of periodic timers and suspending Emacs 22.1) Emacs bug Tracking System

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86tzgq3ymq.fsf@macs.hw.ac.uk \
    --to=jbw@rzlab.ucr.edu \
    --cc=300@emacsbugs.donarmstrong.com \
    --cc=bug-gnu-emacs@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.