[GNC] Could Not Obtain Lock

Chris Mitchell gnucash at chris.oldnest.ca
Fri Aug 26 10:57:56 EDT 2022


If you were dealing with a machine that's left running all the time,
the obvious move would be to adjust the cron job so it runs in the wee
hours of the morning and has lots of time to finish before anyone logs
in, but it sounds like that's not the case here.

The *simple* way would be to do away with the cron job, and change your
Gnucash launcher to run the non-interactive update, wait for it to
finish, and then launch Gnucash normally. The problem with this
approach is that it will run the price update *every* time you launch
Gnucash, not just the first time each day.

A fairly elegant way to solve this, IMO, would be to write a very small
shell script with a loop that checks for the lock file every few
seconds, with a conditional that keeps looping if the lock file is
still there or launches Gnucash if it's not. You'd also want to
increment a counter so the script eventually gives up (in case of a
stale lockfile). If you set up your Gnucash launcher to launch that
shell script instead of launching Gnucash directly, it would automate
the "wait and check" process for you, and Gnucash will just launch
right away if there's no lock file in the way. If you include a couple
of well-placed "echo" statements in the script and set it up to launch
in a terminal window, you can get informative output while it does its
thing. This assumes, of course, that writing a ten-ish line Bash script
and editing your desktop launcher entries are within your comfort zone.

An in-between option would be to leave your Gnucash launcher alone,
remove the cronjob, and add an "autostart" entry to your desktop
environment, which runs the non-interactive update, waits for it to
finish, then launches Gnucash. This would result in a price update *and*
an interactive Gnucash launch *every* time you logged in, which might be
convenient or really annoying, depending on just how often it is that
using Gnucash is the first thing you want to do when logging in to that
machine. But closing and re-launching Gnucash later while still logged
in would *not* trigger another price update with this approach.

The way *I* would probably tackle this would be to replace the cronjob
with a systemd "system" timer/service pair that runs both once a day in
the wee hours of the morning (if the machine is on) and during boot.
Systemd "system" units can trivally be configured to run the update as
your regular user (User=<foo> and Group=<foo>) independent of whether
the user is logged in, and then you could use systemd's sophisticated
dependency (WantedBy=graphical.target — *not* RequiredBy) and ordering
(Before=graphical.target) mechanisms to ensure that the price-update
service has finished (or given up trying) by the time the system
presents a desktop login prompt. If you don't have some familiarity
with systemd unit files, though, you'd be wading into fairly deep water
with this approach. I'd argue that systemd uses a remarkably readable
(and thoroughly documented) configuration language and is *far* less
inherently confusing and idiosyncratic than shell-scripting, but there's
no denying the fact that the scope and complexity of the available
options is overwhelming.

Hope that helps.

Cheers!
 -Chris


On Fri, 26 Aug 2022 15:14:37 +0200
rsbrux via gnucash-user <gnucash-user at gnucash.org> wrote:

> This is an old topic, but I finally figured out what's wrong.
> On the Ubuntu desktop system where I run GnuCash (and little else), I
> set up a cron job to update prices at first logon each day, as
> described here:
> https://wiki.gnucash.org/wiki/Online_Quotes#Updating_enabled_Quotes_from_outside_GnuCash
> Unfortunately, starting GnuCash is often the first thing I want to do
> when I start up the system and I obviously haven't been waiting long
> enough for the cron job to finish. Is there a smarter way to make
> sure prices are collected online without having to wait and check
> that GC has finished the price update before I try to use it
> interactively?
> 
> -----Original Message-----
> From: rsbrux 
> Sent: Monday, June 27, 2022 10:23 AM
> To: gnucash-user at gnucash.org
> Subject: Re: Could Not Obtain Lock 
> 
> I am still on GC v 2.6.19 under Ubuntu 18.04, and experience this
> problem frequently, even when I am *absolutely sure* that GnuCash was
> correctly closed after the last use.  At least in GC 2.6.19 it
> appears that GC does not allow for possible delays in mounting
> volumes in Ubuntu.  The problem has gotten worse since I offloaded
> the GC data file to my NAS.  If I wait to start GC for a few minutes
> after logging in, or start some other applications first, the problem
> does not occur. ------------------------------
> 
> Message: 2
> Date: Sun, 26 Jun 2022 19:53:04 +0000
> From: Gyle McCollam <gmccollam at live.com>
> To: Abe Sternberg <abe.h.sternberg at gmail.com>, Glenn Fowler
> 	<gfowler1 at outlook.com>
> Cc: GnuCash users group <gnucash-user at gnucash.org>
> Subject: Re: [GNC] Could Not Obtain Lock
> Message-ID:
> 	<BLAPR06MB68027ED731C14FF8D870BCCFCAB69 at BLAPR06MB6802.namprd06.prod.outlook.com>
> 	
> Content-Type: text/plain; charset="us-ascii"
> 
> Abe,
> I have had this issue as well.  It usually occurs when I forgot to
> save before closing.  It asks if I want to save, but no matter the
> reply, it doesn't save and doesn't close properly.  I was told it was
> fixed and i am waiting the 4.11 update as well.  Hope this solves
> your issue when released.
> 
> 
> Thank You,
> 
> Gyle McCollam
> 
> Gyle McCollam
> 
> gmccollam at live.com<mailto:gmccollam at gyleshomes.com>           email
> 
> ________________________________
> From: gnucash-user
> <gnucash-user-bounces+gylemc=gmail.com at gnucash.org> on behalf of Abe
> Sternberg <abe.h.sternberg at gmail.com> Sent: Sunday, June 26, 2022
> 3:22 PM To: Glenn Fowler <gfowler1 at outlook.com> Cc: GnuCash users
> group <gnucash-user at gnucash.org> Subject: Re: [GNC] Could Not Obtain
> Lock
> 
> I am using Windows 11.  I try to close GnuCash properly, though there
> have been times when I may not have.  Also, I have had some Windows
> updates while GnuCash was left open.  I will look for the update and
> advise if the error continues.
> 
> Thanks,
> Abe
> 
> On Sun, Jun 26, 2022 at 2:30 PM Glenn Fowler <gfowler1 at outlook.com>
> wrote:
> 
> > Hi Abe,
> >
> > Are you on Windows and how are you closing GnuCash? There was a bug 
> > that would cause this that is fixed in v4.11 being released today
> >
> > On Sun, Jun 26, 2022 at 2:00 PM Abe Sternberg 
> > <abe.h.sternberg at gmail.com>
> > wrote:
> >  
> >> I get this message every time I open GnuCash. It doesn't seem to 
> >> cause any damage but is an annoyance.  Does anyone know what
> >> causes this and how to correct it?
> >>  [image: image.png]
> >>
> >> Abe
> >> _______________________________________________
> >> gnucash-user mailing list
> >> gnucash-user at gnucash.org
> >> To update your subscription preferences or to unsubscribe:
> >> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> >> If you are using Nabble or Gmane, please see 
> >> https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
> >> -----
> >> Please remember to CC this list on all your replies.
> >> You can do this by using Reply-To-List or Reply-All.
> >>  
> >  
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> To update your subscription preferences or to unsubscribe:
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> If you are using Nabble or Gmane, please see
> https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
> ----- Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Sun, 26 Jun 2022 16:39:36 -0400
> From: Michael or Penny Novack <stepbystepfarm at comcast.net>
> To: gnucash-user at gnucash.org
> Subject: Re: [GNC] Could Not Obtain Lock
> Message-ID: <c1b3f5b5-1e15-dd5a-5d09-b3a202011aa8 at comcast.net>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> On 6/26/2022 3:22 PM, Abe Sternberg wrote:
> > I am using Windows 11.  I try to close GnuCash properly, though
> > there have been times when I may not have.  Also, I have had some
> > Windows updates while GnuCash was left open.  I will look for the
> > update and advise if the error continues.
> >
> > Thanks,
> > Abe
> >  
> a) "file in use" << that's what "cannot obtain lock file" means >> if
> CORRECT if you have not closed gnucash properly. This is not unique
> to gnucash but normal for any application using the "lock file"
> method of preventing multiple access to data.
> 
>  ??? IF you are certain the file is not in use (by another instance of
> gnucash) you can override if/when the application provides an easy
> way to do that. Or you can go into the directory (file folder) where
> the data file lives and delete the lock file -- it will always be in
> the same directory.
> 
> b) Do NOT proceed with an operating system update while you have
> application open. Again, this is not specific to gnucash. You should
> have settings related to how updates happen that will allow you to do
> this. Safest if to have the option of doing the updates wit the
> shutdown process.
> 
> Michael D Novack
> 
> PS -- The "file lock" is a method to allow multiple sequential access
> while preventing multiple simultaneous access. When you ask gnucash
> (or any other application using this method) to open a data file, the
> program looks in the same directory for the corresponding lock file.
> If NOT found, it creates that file and proceeds. When gnucash (or any
> other application using this method) closes, the? last thing it does
> is delete the lock file. So if the program does not get to close
> properly, the lock file is left behind,
> 
> 
> 
> 
> ------------------------------
> 
> 
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> To update your subscription preferences or to unsubscribe:
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> -----
> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.



More information about the gnucash-user mailing list