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 312A5429E32 for ; Mon, 27 Jun 2011 20:59:57 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 5FyhbP9H9wPb for ; Mon, 27 Jun 2011 20:59:55 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id EBF06429E25 for ; Mon, 27 Jun 2011 20:59:54 -0700 (PDT) Received: by bwg12 with SMTP id 12so4868895bwg.26 for ; Mon, 27 Jun 2011 20:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=dBMjWqA0GT9dWIMiXYogIyv7Q8oas3PoZUNY/cR7Cx8=; b=gEiorXNPlho2D4z3SccfdLA3Ac8PaFDl4cfKXcm0hMAq1ygXdNxP0OjLT3P3aD6PH4 aXt1KiXC3lEdnCU/d4f3xA78CoMysfq1AY3Uurvjo/VqSmQvR8Tg7/04Jlz4/UHahaGa GDgIZpdCUKu11Bk1Cjiif3zbr+iHZDG65ypow= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; b=qxjE9hdf0CVz8z/cg11wXJFV2poTFMRhhaI4E6yrk8jdh8RG5JiOXpC2iDrmJDKBSb NqGTHS6bpJDnyxX8eVtujwerEHgHvtAgjhXTLvJr+dXRNgwUDg/hkisu0EdjWs4BpzRk AG48ugxD84Cy3L+qUFABD21YTUtb9g1LWcsDM= Received: by 10.204.128.90 with SMTP id j26mr5070053bks.116.1309233593127; Mon, 27 Jun 2011 20:59:53 -0700 (PDT) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id k5sm2869834bka.5.2011.06.27.20.59.51 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 27 Jun 2011 20:59:52 -0700 (PDT) From: Dmitry Kurochkin To: Austin Clements Subject: Re: [PATCH 2/2] test: use emacsclient(1) for Emacs tests In-Reply-To: <20110628034937.GB4120@mit.edu> References: <1309132379-24089-1-git-send-email-dmitry.kurochkin@gmail.com> <1309146846-30991-1-git-send-email-dmitry.kurochkin@gmail.com> <1309146846-30991-2-git-send-email-dmitry.kurochkin@gmail.com> <87hb7byqge.fsf@gmail.com> <87d3hyzs1c.fsf@gmail.com> <20110628034937.GB4120@mit.edu> User-Agent: Notmuch/0.5-275-g75c95e5 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Tue, 28 Jun 2011 07:59:48 +0400 Message-ID: <87aad2zjuz.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: notmuch@notmuchmail.org 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: Tue, 28 Jun 2011 03:59:57 -0000 On Mon, 27 Jun 2011 23:49:37 -0400, Austin Clements wrote: > Quoth Dmitry Kurochkin on Jun 28 at 5:03 am: > > > > The only way I know to > > > > reliably kill a child process is to open a pipe to it and have it exit > > > > on its own when it reads EOF. Unfortunately, I couldn't find a way to > > > > do this with an emacs daemon (it appears daemon mode aggressively > > > > cleans up things like pipes), but here's a different approach: > > > > > > > > coproc emacs --batch --eval "(while t (eval (read)))" > > > > EMACSFD=${COPROC[1]} > > > > trap "echo '(kill-emacs)' >&$EMACSFD" EXIT > > > > > > > > echo '(message "Hi")' >&$EMACSFD > > > > # ... > > > > > > > > This is, basically, a poor man's emacs server, but the coprocess pipe > > > > binds it tightly to the shell. If the shell exits for *any* reason, > > > > the pipe will be closed by the kernel, emacs will read an EOF, and > > > > exit. > > > > > > I like this idea. > > > > > > > The trap is there just to cleanly shut down in case of a normal > > > > exit [1]. > > > > > > For normal exit we should just put this into test_done. Otherwise it is > > > not a normal exit and we do not care about Emacs error message. No? > > > > > > > This also has the advantage that read-from-minibuffer still > > > > works: > > > > > > > > echo '(message (read-from-minibuffer ""))' >&$EMACSFD > > > > echo 'Test' >&$EMACSFD > > > > > > > > Thoughts? > > > > > > > > > > I like it and I will implement it. Thanks for the idea. > > > > > > > While implementing the idea, I stumbled upon a problem: we need to know > > when Emacs finished what we echoed or failed with an error. At the > > moment tests fail because they check for OUTPUT before Emacs creates it. > > > > We can tell Emacs to print some special marker and wait for it. But > > there may be exceptions and errors which may make it difficult. I did > > not found a good solution yet. Would love to hear your thoughts :) > > Oof, yes, of course. How about making the one-line poor man's emacs > server slightly less poor? Use a FIFO to communicate completion. > Something like, > > EMACSDONE=$TEST_DIRECTORY/emacsdone > mkfifo $EMACSDONE > coproc emacs --batch --eval '(while t (eval (read)) (write-region "\n" nil "'$EMACSDONE'" t 0))' > EMACSFD=${COPROC[1]} > > test_emacs() { > echo "$1" >&$EMACSFD > read <$EMACSDONE > } > > test_emacs '(sleep-for 2)' > test_emacs '(message "Hi")' > > echo '(kill-emacs)' >&$EMACSFD I am sure that would work, but I do not like the complexity. How about getting back to standard emacsclient and running a watchdog in the emacs? Like: (defun orphan-watchdog (pid) "Periodically check that the process with id PID is still running, quit if it terminated." (if (not (process-attributes pid)) (kill-emacs) (run-at-time "1 min" nil orphan-watchdog pid))) This function (or my other changes) do not work (by yet unknown reason :)), but you get the idea. Regards, Dmitry