bug#30080: 24.5; write-region can reset idle time

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Cecil Westerhof-4

It is possible that write-region resets idle time. As soon as I use
one or both of the following in my .emacs:
    (desktop-save-mode 1)
    (global-auto-revert-mode 1)

The idle time is reset when calling write-region.

To reproduce put one or both into .emacs.
Define the following function:
    (defun write-region-problem ()
      (message (format "Before: %s %s" (current-time) (current-idle-time)))
      (write-region "Just a test\n" nil "~/problem.log" t 0)
      (message (format "After:  %s %s" (current-time) (current-idle-time)))
      )

And execute:
    (setq timer-object (run-with-timer 30 30 'write-region-problem))

You then get output like the following:
    Before: (23127 39977 941713 503000) (0 29 994274 462000)
    After:  (23127 39977 982179 647000) (0 30 34741 483000)
    Before: (23127 40007 940217 421000) (0 29 946739 305000)
    After:  (23127 40007 981669 405000) (0 29 988192 219000)
    Before: (23127 40037 941670 105000) (0 29 944688 557000)
    After:  (23127 40037 991646 30000) (0 29 994665 603000)
    Before: (23127 40067 941685 17000) (0 29 938036 13000)
    After:  (23127 40067 992876 336000) (0 29 989228 329000)
    Before: (23127 40097 939595 311000) (0 29 936576 788000)
    After:  (23127 40097 977542 689000) (0 29 974525 333000)


If both are not defined, you get output like:
    Before: (23127 47206 936031 250000) (0 24 841129 146000)
    After:  (23127 47206 937987 23000) (0 24 843085 910000)
    Before: (23127 47236 936555 313000) (0 54 841653 459000)
    After:  (23127 47236 938648 51000) (0 54 843747 333000)
    Before: (23127 47266 935235 63000) (0 84 840333 256000)
    After:  (23127 47266 937094 166000) (0 84 842192 826000)
    Before: (23127 47296 936545 234000) (0 114 841643 122000)
    After:  (23127 47296 938517 313000) (0 114 843616 494000)


Before 19 December I did not have this problem. So it is recently
introduced.

My version of Emacs:
    GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-09-12 on hullmann, modified by Debian

--
Cecil Westerhof
Senior Software Engineer
M [hidden email]

LinkedIn: http://www.linkedin.com/in/cecilwesterhof



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Stefan Monnier
>     (global-auto-revert-mode 1)

Ha, I think you have your culprit right there: my crystal ball says that
if you have auto-revert active on the file you modify with
`write-region` (or maybe even just a file in the same directory) any
modification to the file (e.g. via `write-region`) will send
a pseudo-event, which Emacs's command-loop will confuse for an actual
user event!


        Stefan



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Cecil Westerhof-4
Stefan Monnier <[hidden email]> writes:

>>     (global-auto-revert-mode 1)
>
> Ha, I think you have your culprit right there: my crystal ball says that
> if you have auto-revert active on the file you modify with
> `write-region` (or maybe even just a file in the same directory) any
> modification to the file (e.g. via `write-region`) will send
> a pseudo-event, which Emacs's command-loop will confuse for an actual
> user event!

The problem being that until the 19th of December it worked without a
problem. I did not change my .emacs.

Also (desktop-save-mode 1) has the same effect. When I do not have
(global-auto-revert-mode 1), but I do have (desktop-save-mode 1), then
also write-region will reset idle time.


It is even more funny: when I play a video with mpv, idle time is also
reset. And this I find really odd.

--
Cecil Westerhof
Senior Software Engineer
M [hidden email]

LinkedIn: http://www.linkedin.com/in/cecilwesterhof



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Eli Zaretskii
> From: Cecil Westerhof <[hidden email]>
> Date: Fri, 12 Jan 2018 02:36:52 +0100
> Cc: [hidden email]
>
> Also (desktop-save-mode 1) has the same effect. When I do not have
> (global-auto-revert-mode 1), but I do have (desktop-save-mode 1), then
> also write-region will reset idle time.

desktop-save-mode writes the desktop file from time to time, and it
uses an idle timer, so I think this explains that.



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Cecil Westerhof-4
Eli Zaretskii <[hidden email]> writes:

>> From: Cecil Westerhof <[hidden email]>
>> Date: Fri, 12 Jan 2018 02:36:52 +0100
>> Cc: [hidden email]
>>
>> Also (desktop-save-mode 1) has the same effect. When I do not have
>> (global-auto-revert-mode 1), but I do have (desktop-save-mode 1), then
>> also write-region will reset idle time.
>
> desktop-save-mode writes the desktop file from time to time, and it
> uses an idle timer, so I think this explains that.

I have two problems with that:
- I do not think that it is done every minute, or less. And the reset
  is done on the moment of the write-region of my command. So does not
  directly relate to the writing of the desktop file.
- Before 19 December I did not have this behaviour. So it started
  after an update. It did not work like this for more as five years,
  but started the 19th of December 2017.

--
Cecil Westerhof
Senior Software Engineer
M [hidden email]

LinkedIn: http://www.linkedin.com/in/cecilwesterhof



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Eli Zaretskii
> From: Cecil Westerhof <[hidden email]>
> Cc: [hidden email],  [hidden email]
> Date: Fri, 12 Jan 2018 11:36:15 +0100
>
> > desktop-save-mode writes the desktop file from time to time, and it
> > uses an idle timer, so I think this explains that.
>
> I have two problems with that:
> - I do not think that it is done every minute, or less. And the reset
>   is done on the moment of the write-region of my command. So does not
>   directly relate to the writing of the desktop file.

desktop.el auto-saves when something in the window/buffer
configuration changes, no matter how frequently that happens.  The
idle timer run by desktop.el uses the same timeout value as auto-save,
which is 30 sec by default.  Maybe these facts will allow you to find
out why desktop-save-mode has that effect.

> - Before 19 December I did not have this behaviour. So it started
>   after an update. It did not work like this for more as five years,
>   but started the 19th of December 2017.

I guess you will have to find out what changed with that update.  No
one else except yourself can do that.  Maybe it's some change in the
kernel, or in glibc, or in inotify.

FWIW, I cannot reproduce your problem, neither in "emacs -Q" nor if I
turn on global-auto-revert-mode or desktop-save-mode, neither on
GNU/Linux nor on MS-Windows.  So this is most probably something
specific to your system.

What is the value of system-configuration-features in that build, btw?
Maybe some of the features is responsible for that, and my builds are
without it.



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Cecil Westerhof-4
Eli Zaretskii <[hidden email]> writes:

>> From: Cecil Westerhof <[hidden email]>
>> Cc: [hidden email],  [hidden email]
>> Date: Fri, 12 Jan 2018 11:36:15 +0100
>>
>> > desktop-save-mode writes the desktop file from time to time, and it
>> > uses an idle timer, so I think this explains that.
>>
>> I have two problems with that:
>> - I do not think that it is done every minute, or less. And the reset
>>   is done on the moment of the write-region of my command. So does not
>>   directly relate to the writing of the desktop file.
>
> desktop.el auto-saves when something in the window/buffer
> configuration changes, no matter how frequently that happens.  The
> idle timer run by desktop.el uses the same timeout value as auto-save,
> which is 30 sec by default.  Maybe these facts will allow you to find
> out why desktop-save-mode has that effect.

But it is not desktop-save-mode that does it. As long as I do no
write-region the idle-time is not reset. So desktop-save-mode does not
reset idle time, but desktop-save-mode makes write region reset idle
time.

>> - Before 19 December I did not have this behaviour. So it started
>>   after an update. It did not work like this for more as five years,
>>   but started the 19th of December 2017.
>
> I guess you will have to find out what changed with that update.  No
> one else except yourself can do that.  Maybe it's some change in the
> kernel, or in glibc, or in inotify.

Well, I have to ask on the Debian mailing list then.


> FWIW, I cannot reproduce your problem, neither in "emacs -Q" nor if I
> turn on global-auto-revert-mode or desktop-save-mode, neither on
> GNU/Linux nor on MS-Windows.  So this is most probably something
> specific to your system.

I just tried it on an Ubuntu system and I get the same results.


> What is the value of system-configuration-features in that build, btw?
> Maybe some of the features is responsible for that, and my builds are
> without it.

How do I get that?

--
Cecil Westerhof
Senior Software Engineer
M [hidden email]

LinkedIn: http://www.linkedin.com/in/cecilwesterhof



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Stefan Monnier
In reply to this post by Cecil Westerhof-4
>>>     (global-auto-revert-mode 1)
>> Ha, I think you have your culprit right there: my crystal ball says that
>> if you have auto-revert active on the file you modify with
>> `write-region` (or maybe even just a file in the same directory) any
>> modification to the file (e.g. via `write-region`) will send
>> a pseudo-event, which Emacs's command-loop will confuse for an actual
>> user event!
> The problem being that until the 19th of December it worked without a
> problem. I did not change my .emacs.

And I see also that keyboard.c does seem to do it right:

      if (CONSP (c)
          && (EQ (XCAR (c), Qselect_window)
#ifdef HAVE_DBUS
              || EQ (XCAR (c), Qdbus_event)
#endif
#ifdef USE_FILE_NOTIFY
              || EQ (XCAR (c), Qfile_notify)
#endif
              || EQ (XCAR (c), Qconfig_changed_event))
          && !end_time)
        /* We stopped being idle for this event; undo that.  This
           prevents automatic window selection (under
           mouse-autoselect-window) from acting as a real input event, for
           example banishing the mouse under mouse-avoidance-mode.  */
        timer_resume_idle ();

Hmm...

> It is even more funny: when I play a video with mpv, idle time is also
> reset. And this I find really odd.

Can you try to run Emacs under GDB?
Then start Emacs to try and reproduce the problem with mpv.
Once ready to start mpv, hit `C-c C-z` in GDB, then type

    break timer_stop_idle
    continue

then launch mpv and try to see the backtrace (with command `bt`) when
the timer_stop_idle breakpoint is triggered.
[ Then again, maybe this will trigger all the time, but is a false
  alarm because it would be undone right after by the above code.  ]


        Stefan



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Cecil Westerhof-4
Stefan Monnier <[hidden email]> writes:

>> It is even more funny: when I play a video with mpv, idle time is also
>> reset. And this I find really odd.
>
> Can you try to run Emacs under GDB?
> Then start Emacs to try and reproduce the problem with mpv.
> Once ready to start mpv, hit `C-c C-z` in GDB, then type
>
>     break timer_stop_idle
>     continue
>
> then launch mpv and try to see the backtrace (with command `bt`) when
> the timer_stop_idle breakpoint is triggered.
> [ Then again, maybe this will trigger all the time, but is a false
>   alarm because it would be undone right after by the above code.  ]

And it is funnier still: I found out that this only happens when mpv
is started when clicking on a file in KTorrent. If I click om a file
in Thunar, or start mpv from the command line it does not happen.

I will try to do what you asked this weekend.

--
Cecil Westerhof
Senior Software Engineer
M [hidden email]

LinkedIn: http://www.linkedin.com/in/cecilwesterhof



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Glenn Morris-3
In reply to this post by Cecil Westerhof-4
Cecil Westerhof wrote:

>> What is the value of system-configuration-features in that build, btw?
>> Maybe some of the features is responsible for that, and my builds are
>> without it.
>
> How do I get that?

Upgrade to at least Emacs 25.1. Preferably 25.3.
(Is it just me who thinks investigating an Emacs 24.5 problem isn't
productive?)



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Cecil Westerhof-4
Glenn Morris <[hidden email]> writes:

> Cecil Westerhof wrote:
>
>>> What is the value of system-configuration-features in that build, btw?
>>> Maybe some of the features is responsible for that, and my builds are
>>> without it.
>>
>> How do I get that?
>
> Upgrade to at least Emacs 25.1. Preferably 25.3.
> (Is it just me who thinks investigating an Emacs 24.5 problem isn't
> productive?)

Debian is always a bit behind, but I could look into upgrading
manually.

--
Cecil Westerhof
Senior Software Engineer
M [hidden email]

LinkedIn: http://www.linkedin.com/in/cecilwesterhof



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Stefan Monnier
>> (Is it just me who thinks investigating an Emacs 24.5 problem isn't
>> productive?)

Oh, my, I didn't even notice.

> Debian is always a bit behind, but I could look into upgrading
> manually.

Debian testing has 25.2, please try at least that version.


        Stefan



Reply | Threaded
Open this post in threaded view
|

bug#30080: 24.5; write-region can reset idle time

Cecil Westerhof-4
Stefan Monnier <[hidden email]> writes:

>>> (Is it just me who thinks investigating an Emacs 24.5 problem isn't
>>> productive?)
>
> Oh, my, I didn't even notice.
>
>> Debian is always a bit behind, but I could look into upgrading
>> manually.
>
> Debian testing has 25.2, please try at least that version.

Stable has also 25.1.1. I had to install emacs25 instead of emacs.
Done that and both problems disappeared. In a way this keeps me
wondering how it could appear and disappear, but I think I let it go.
;-)

Is there a reason to go to 25.2 instead of 25.1.1, or is this good
enough?

--
Cecil Westerhof
Senior Software Engineer
M [hidden email]

LinkedIn: http://www.linkedin.com/in/cecilwesterhof