unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: James Vasile <james@hackervisions.org>
To: notmuch@notmuchmail.org
Subject: Re: [PATCH] Calls to notmuch get queued and executed	asynchronously.
Date: Wed, 24 Feb 2010 14:28:16 -0500	[thread overview]
Message-ID: <878waiwi0f.wl%james@hackervisions.org> (raw)
In-Reply-To: <87vddnlxos.wl%james@hackervisions.org>

Sleep between retrying asynchronous notmuch commands and check for
notmuch-process before firing off a new one

If the db is locked when notmuch tries to write to it, an error is
reported to the client (in this case, notmuch.el).  Instead of
accepting that error, wait a small amount of time and then try again.

Also, don't start multiple asynchronous processes.
---
 notmuch.el |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 7fc63e9..31e89b9 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -1402,9 +1402,14 @@ args is a list of arguments to notmuch.  ex: (\"tag\" \"+list\"
 
 Calls to notmuch are queued and called asynchronously."
   (setq notmuch-asynch-queue (append notmuch-asynch-queue (list args)))
-  (when (= (length notmuch-asynch-queue) 1)
+  (when (and (= (length notmuch-asynch-queue) 1)
+	     (not (get-process "notmuch-process")))
     (apply 'notmuch-call-notmuch-process-asynch (pop notmuch-asynch-queue))))
-  
+
+(defun notmuch-asynch-sleep-sentinel (process event)
+  "After we sleep, try a command from the notmuch queue"
+  (apply 'notmuch-call-notmuch-process-asynch (pop notmuch-asynch-queue)))
+
 (defun notmuch-call-notmuch-process-asynch-sentinel (process event)
   "Handle the exit of a notmuch asynch process.
 
@@ -1416,11 +1421,16 @@ command, try it again."
     (if (= (process-exit-status process) 0)
 	(kill-buffer (buffer-name (process-buffer process)))
 	(if (search-forward "Unable to acquire database write lock" nil t)
-	    (apply 'notmuch-call-notmuch-process-asynch (cdr (process-command process)))
+	    (progn
+	      (push (cdr (process-command process)) notmuch-asynch-queue)
+	      (set-process-sentinel 
+	       (start-process "notmuch-sleep" nil "sleep" "3")
+	       'notmuch-asynch-sleep-sentinel))
 	    (error (format "%s: %s" (join-string-list (process-command process))
 			   (buffer-string))))))
   (apply 'notmuch-call-notmuch-process-asynch (pop notmuch-asynch-queue)))
 
+
 (defun notmuch-call-notmuch-process (&rest args)
   "Synchronously invoke \"notmuch\" with the given list of arguments.
 
-- 
1.6.3.3

  reply	other threads:[~2010-02-24 19:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-23 16:32 [PATCH] Calls to notmuch get queued and executed asynchronously James Vasile
2010-02-24 19:28 ` James Vasile [this message]
2011-10-21 20:50 ` Daniel Schoepe
2011-12-30 10:52   ` David Edmondson
2011-12-30 19:21     ` Aaron Ecay
2012-01-03 10:58       ` David Edmondson
2012-10-12  2:21 ` Ethan Glasser-Camp
2012-10-12 16:58   ` David Bremner

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://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878waiwi0f.wl%james@hackervisions.org \
    --to=james@hackervisions.org \
    --cc=notmuch@notmuchmail.org \
    /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://yhetil.org/notmuch.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).