Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4A82E431FBC for ; Wed, 24 Feb 2010 11:28:27 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.422 X-Spam-Level: X-Spam-Status: No, score=-0.422 tagged_above=-999 required=5 tests=[AWL=-0.523, BAYES_50=0.001, RDNS_DYNAMIC=0.1] autolearn=no Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qmHORpox0dLR for ; Wed, 24 Feb 2010 11:28:26 -0800 (PST) Received: from hackervisions.org (67-207-143-141.slicehost.net [67.207.143.141]) by olra.theworths.org (Postfix) with ESMTP id DD272431FAE for ; Wed, 24 Feb 2010 11:28:26 -0800 (PST) Received: from john-marshall.sflc.info ([216.27.154.200] helo=wyzanski.hackervisions.org) by hv with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1NkMuF-0006dk-TC; Wed, 24 Feb 2010 14:28:24 -0500 Date: Wed, 24 Feb 2010 14:28:16 -0500 Message-ID: <878waiwi0f.wl%james@hackervisions.org> From: James Vasile To: notmuch@notmuchmail.org In-Reply-To: <87vddnlxos.wl%james@hackervisions.org> References: <87vddnlxos.wl%james@hackervisions.org> X-Mailer: Wanderlust/2.15.6 User-Agent: SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 Emacs/23.1 (i486-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Subject: Re: [notmuch] [PATCH] Calls to notmuch get queued and executed asynchronously. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Feb 2010 19:28:27 -0000 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