unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: don@donarmstrong.com (Emacs bug Tracking System)
To: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#300: marked as done (strange interaction of periodic timers  and suspending Emacs 22.1)
Date: Thu, 29 May 2008 20:10:04 -0700	[thread overview]
Message-ID: <handler.300.D300.12121167245855.ackdone@emacsbugs.donarmstrong.com> (raw)
In-Reply-To: 86tzgq3ymq.fsf@macs.hw.ac.uk

[-- Attachment #1: Type: text/plain, Size: 917 bytes --]


Your message dated Thu, 29 May 2008 23:05:14 -0400
with message-id <jwvr6bk7arz.fsf-monnier+emacsbugreports@gnu.org>
and subject line Re: bug#300: strange interaction of periodic timers and suspending Emacs 22.1
has caused the Emacs bug report #300,
regarding strange interaction of periodic timers and suspending Emacs 22.1
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact don@donarmstrong.com
immediately.)


-- 
300: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=300
Emacs Bug Tracking System
Contact don@donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 6894 bytes --]

From: Joe Wells <jbw@localhost.localdomain>
To: bug-gnu-emacs@gnu.org
Subject: 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>

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.





[-- Attachment #3: Type: message/rfc822, Size: 1935 bytes --]

From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Joe Wells <jbw@macs.hw.ac.uk>
Cc: 300-done@emacsbugs.donarmstrong.com
Subject: Re: bug#300: strange interaction of periodic timers and suspending Emacs 22.1
Date: Thu, 29 May 2008 23:05:14 -0400
Message-ID: <jwvr6bk7arz.fsf-monnier+emacsbugreports@gnu.org>

> The case that bugs me enough to care is that I have a timer that
> invokes desktop-save roughly every 5 minutes.  (My scheme is a bit
> more clever than that and tries to save during idle times, but if it
> can't save during an idle time it will still ensure the desktop file
> is saved at least every 5 minutes.)  My desktop file is quite big

Of course, beside fixing your code to not use a repeating timer, but
a one-shot timer which you manually re-arm at the end, it turns out we
already have a variable to control this problem:

    timer-max-repeats


-- Stefan


      parent reply	other threads:[~2008-05-30  3:10 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 ` bug#300: strange interaction of periodic timers and suspending Emacs 22.1 Joe Wells
2008-05-23 21:17   ` 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   ` Emacs bug Tracking System [this message]

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=handler.300.D300.12121167245855.ackdone@emacsbugs.donarmstrong.com \
    --to=don@donarmstrong.com \
    --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).