all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Avoid asking to user for lock (ask-user-about-lock)
@ 2015-09-24 12:39 David Capello
  2015-09-24 15:52 ` Stefan Monnier
  2015-09-24 20:42 ` David Capello
  0 siblings, 2 replies; 9+ messages in thread
From: David Capello @ 2015-09-24 12:39 UTC (permalink / raw)
  To: help-gnu-emacs

Hi there,

I've a package (keyfreq) that tries to add data to a file each X seconds.
To do this it has to create a lock file, write the file, and release/delete
the lock. If two instances of Emacs are running, both instances will try
to write in the file at certain point. And here is where I'm having
troubles
(this was not a problem in Emacs 24.3, but now it is on 24.5).

The problem is here:
https://github.com/dacap/keyfreq/blob/master/keyfreq.el#L427

I'm trying to redefine ask-user-about-lock temporarily so it doesn't
ask to overwrite the .lock file if it already exists (if the lock already
exist, we just "do nothing"/"wait next timeout", because the file is
locked).
Anyway it looks that sometimes, this redefinition doesn't work correctly.

I would like to know if there is a way/common pattern to handle
this kind of situations where two or more instances of Emacs are trying
to add data to a file, and if they cannot get the lock, they just do
nothing and can try it later.

- David


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-24 12:39 Avoid asking to user for lock (ask-user-about-lock) David Capello
@ 2015-09-24 15:52 ` Stefan Monnier
  2015-09-24 20:42 ` David Capello
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2015-09-24 15:52 UTC (permalink / raw)
  To: help-gnu-emacs

> The problem is here:
> https://github.com/dacap/keyfreq/blob/master/keyfreq.el#L427

I think rather than override ask-user-about-lock you want to use the
MUSTBENEW argument:

 (write-region (number-to-string (emacs-pid)) nil
               keyfreq-file-lock nil 'nomessage nil nil 'excl)


-- Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-24 12:39 Avoid asking to user for lock (ask-user-about-lock) David Capello
  2015-09-24 15:52 ` Stefan Monnier
@ 2015-09-24 20:42 ` David Capello
  2015-09-24 21:10   ` Stefan Monnier
  1 sibling, 1 reply; 9+ messages in thread
From: David Capello @ 2015-09-24 20:42 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: monnier

> > The problem is here:
> > https://github.com/dacap/keyfreq/blob/master/keyfreq.el#L427
>
> I think rather than override ask-user-about-lock you want to use the
> MUSTBENEW argument:
>
>  (write-region (number-to-string (emacs-pid)) nil
>                keyfreq-file-lock nil 'nomessage nil nil 'excl)

I think there is one extra nil, so I've used

  (write-region (number-to-string (emacs-pid)) nil
                keyfreq-file-lock nil 'nomessage nil 'excl)

And it seems to work, but I still getting some messages like:

  .../.emacs.keyfreq.lock locked by david@pc (pid 9076): (s, q, p, ?)?

in the minibuf.

PS: Please CC me because I'm not subscribed to the list.

- David

On Thu, Sep 24, 2015 at 9:39 AM, David Capello <davidcapello@gmail.com>
wrote:

> Hi there,
>
> I've a package (keyfreq) that tries to add data to a file each X seconds.
> To do this it has to create a lock file, write the file, and release/delete
> the lock. If two instances of Emacs are running, both instances will try
> to write in the file at certain point. And here is where I'm having
> troubles
> (this was not a problem in Emacs 24.3, but now it is on 24.5).
>
> The problem is here:
> https://github.com/dacap/keyfreq/blob/master/keyfreq.el#L427
>
> I'm trying to redefine ask-user-about-lock temporarily so it doesn't
> ask to overwrite the .lock file if it already exists (if the lock already
> exist, we just "do nothing"/"wait next timeout", because the file is
> locked).
> Anyway it looks that sometimes, this redefinition doesn't work correctly.
>
> I would like to know if there is a way/common pattern to handle
> this kind of situations where two or more instances of Emacs are trying
> to add data to a file, and if they cannot get the lock, they just do
> nothing and can try it later.
>
> - David
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-24 20:42 ` David Capello
@ 2015-09-24 21:10   ` Stefan Monnier
  2015-09-24 21:33     ` David Capello
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2015-09-24 21:10 UTC (permalink / raw)
  To: David Capello; +Cc: help-gnu-emacs

> And it seems to work, but I still getting some messages like:

>   .../.emacs.keyfreq.lock locked by david@pc (pid 9076): (s, q, p, ?)?

> in the minibuf.

When?


        Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-24 21:10   ` Stefan Monnier
@ 2015-09-24 21:33     ` David Capello
  2015-09-25  1:22       ` Stefan Monnier
  2015-09-25  2:08       ` David Capello
  0 siblings, 2 replies; 9+ messages in thread
From: David Capello @ 2015-09-24 21:33 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

On Thu, Sep 24, 2015 at 6:10 PM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > And it seems to work, but I still getting some messages like:
> >   .../.emacs.keyfreq.lock locked by david@pc (pid 9076): (s, q, p, ?)?
> > in the minibuf.
>
> When?
>

When write-region is called by multiple Emacs instances at the same time.
You can try it by yourself with the latest keyfreq master commit, using this
configuration:

(require 'keyfreq)
(setq keyfreq-autosave-timeout 1)  ;; I'm using 1 second to test the lock
mechanism
(keyfreq-mode 1)
(keyfreq-autosave-mode 1)

After that you can open two instances and try to write in both of then
quickly random
characters in the scratch buffer (you will need to do it quickly and
switching between
both instances).

- David


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-24 21:33     ` David Capello
@ 2015-09-25  1:22       ` Stefan Monnier
  2015-09-25  2:08       ` David Capello
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2015-09-25  1:22 UTC (permalink / raw)
  To: help-gnu-emacs

>> > And it seems to work, but I still getting some messages like:
>> >   .../.emacs.keyfreq.lock locked by david@pc (pid 9076): (s, q, p, ?)?
>> > in the minibuf.
>> When?
> When write-region is called by multiple Emacs instances at the same time.

Do you know because you've seen the backtraces, or do you just think
that's what happens?

Without backtraces showing clearly when this prompt pops up, it's hard
to know what needs to be done.


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-24 21:33     ` David Capello
  2015-09-25  1:22       ` Stefan Monnier
@ 2015-09-25  2:08       ` David Capello
  2015-09-25 11:05         ` Fwd: " David Capello
  1 sibling, 1 reply; 9+ messages in thread
From: David Capello @ 2015-09-25  2:08 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

>>> > And it seems to work, but I still getting some messages like:
>>> >   .../.emacs.keyfreq.lock locked by address@hidden (pid 9076): (s, q, p,
>>> > ?)?
>>> > in the minibuf.
>>> When?
>> When write-region is called by multiple Emacs instances at the same time.
>
> Do you know because you've seen the backtraces, or do you just think
> that's what happens?
>
> Without backtraces showing clearly when this prompt pops up, it's hard
> to know what needs to be done.

Backtraces, here a screenshot:
http://i.imgur.com/VqoL7Fe.png

- David



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Fwd: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-25  2:08       ` David Capello
@ 2015-09-25 11:05         ` David Capello
  2015-10-20 14:20           ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: David Capello @ 2015-09-25 11:05 UTC (permalink / raw)
  To: help-gnu-emacs

>>> > And it seems to work, but I still getting some messages like:
>>> >   .../.emacs.keyfreq.lock locked by address@hidden (pid 9076): (s, q, p,
>>> > ?)?
>>> > in the minibuf.
>>> When?
>> When write-region is called by multiple Emacs instances at the same time.
>
> Do you know because you've seen the backtraces, or do you just think
> that's what happens?
>
> Without backtraces showing clearly when this prompt pops up, it's hard
> to know what needs to be done.

Backtraces, here a screenshot:
http://i.imgur.com/VqoL7Fe.png

- David



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fwd: Avoid asking to user for lock (ask-user-about-lock)
  2015-09-25 11:05         ` Fwd: " David Capello
@ 2015-10-20 14:20           ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2015-10-20 14:20 UTC (permalink / raw)
  To: help-gnu-emacs

> Backtraces, here a screenshot:
> http://i.imgur.com/VqoL7Fe.png

Hmm, this looks like a plain bug: it makes no sense to check locks when
writing with `excl'.  Please report it with M-x report-emacs-bug (but
please copy&paste the *text* of backtrace rather than putting a link to
a website that holds a PNG of the backtrace: several Emacs developers
often work offline and/or in text-only environments).


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-20 14:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-24 12:39 Avoid asking to user for lock (ask-user-about-lock) David Capello
2015-09-24 15:52 ` Stefan Monnier
2015-09-24 20:42 ` David Capello
2015-09-24 21:10   ` Stefan Monnier
2015-09-24 21:33     ` David Capello
2015-09-25  1:22       ` Stefan Monnier
2015-09-25  2:08       ` David Capello
2015-09-25 11:05         ` Fwd: " David Capello
2015-10-20 14:20           ` Stefan Monnier

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.