Subject: bug#4954: 23.1; Emacs hangs when two run-at-time calls in effect

From: Lennart Borgman <[email-masked]>
Date: Thu, 19 Nov 2009 00:36:34 +0100

On Wed, Nov 18, 2009 at 4:41 PM, Sullivan Beck <[email-masked]> wrote:
> I wrote two simple emacs extensions, both of which use the run-at-time
> function periodically write some information to a file. When one or the
> other is loaded, emacs works fine. When both are loaded, emacs will work
> fine for a while, and then suddently start behaving very sluggishly.
> Keyboard input will not be printed on the screen for 2-4 seconds. It
> never seems to recover (though the periodic work should only take a
> fraction of a second) and eventually, I have to kill emacs and restart.
>
> I'll include both extensions below, though I don't believe that either
> of them are directly related to the cause of the problem... it just
> happened that they both use run-at-time.

Hi Sullivan,

I do not know what causes the hang, but I can guess. In both your
extensions you are saving data to a file. I wonder if that operation
is syncronous? If it is then all Emacs can do is to wait there. (File
operations can be both async and sync and I do not know what Emacs is
doing.)

A way to work around the trouble is perhaps to rewrite your scheduling
of the saving operations. Here is one suggestion:

- Instead of saving immediately in the timer start a second timer with
run-with-idle-timer.
- In that timer do the saving.

This makes the chance that the saving will occur while you are typing
a bit smaller, but it does not avoid the trouble totally.