From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Phil Sainty Newsgroups: gmane.emacs.bugs Subject: bug#14820: 24.3; elisp manual: How to write good idle timer worker functions? Date: Sat, 13 Jul 2013 18:38:48 +1200 Message-ID: <51E0F5F8.10206@orcon.net.nz> References: <51DABDE6.10904@orcon.net.nz> <50216.121.99.89.166.1373470285.squirrel@mail.orcon.net.nz> <87ppup2p1z.fsf@tanger.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1373697612 6037 80.91.229.3 (13 Jul 2013 06:40:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Jul 2013 06:40:12 +0000 (UTC) Cc: 14820@debbugs.gnu.org To: Daimrod Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 13 08:40:13 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UxtV5-000324-2E for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Jul 2013 08:40:11 +0200 Original-Received: from localhost ([::1]:36938 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxtV4-000112-6z for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Jul 2013 02:40:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxtUz-0000y1-Ty for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2013 02:40:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxtUy-000635-Mt for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2013 02:40:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:57528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxtUy-00062m-K6 for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2013 02:40:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1UxtUx-0003Ue-6L for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2013 02:40:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Phil Sainty Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Jul 2013 06:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14820 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 14820-submit@debbugs.gnu.org id=B14820.137369755213339 (code B ref 14820); Sat, 13 Jul 2013 06:40:02 +0000 Original-Received: (at 14820) by debbugs.gnu.org; 13 Jul 2013 06:39:12 +0000 Original-Received: from localhost ([127.0.0.1]:51844 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UxtU7-0003T2-OP for submit@debbugs.gnu.org; Sat, 13 Jul 2013 02:39:12 -0400 Original-Received: from nctlincom01.orcon.net.nz ([60.234.4.69]:34602) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UxtU0-0003SH-8b for 14820@debbugs.gnu.org; Sat, 13 Jul 2013 02:39:06 -0400 Original-Received: from mx1.orcon.net.nz (mx1.orcon.net.nz [219.88.242.51]) by nctlincom01.orcon.net.nz (8.14.3/8.14.3/Debian-9.4) with ESMTP id r6D6sqPe003026 for <14820@debbugs.gnu.org>; Sat, 13 Jul 2013 18:54:52 +1200 Original-Received: from Debian-exim by mx1.orcon.net.nz with local (Exim 4.69) (envelope-from ) id 1UxtTu-0006Lj-B4 for 14820@debbugs.gnu.org; Sat, 13 Jul 2013 18:38:58 +1200 Original-Received: from [121.99.89.166] (helo=[10.1.1.3]) by mx1.orcon.net.nz with esmtpa (Exim 4.69) (envelope-from ) id 1UxtTt-0006LH-Tv; Sat, 13 Jul 2013 18:38:57 +1200 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: <87ppup2p1z.fsf@tanger.home> X-DSPAM-Check: by mx1.orcon.net.nz on Sat, 13 Jul 2013 18:38:58 +1200 X-DSPAM-Result: Innocent X-DSPAM-Processed: Sat Jul 13 18:38:58 2013 X-DSPAM-Confidence: 0.7006 X-DSPAM-Probability: 0.0000 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN, default) X-CanIt-Geo: ip=121.99.89.166; country=NZ; region=E7; city=Auckland; latitude=-36.8667; longitude=174.7667; http://maps.google.com/maps?q=-36.8667,174.7667&z=6 X-CanItPRO-Stream: base:default X-Canit-Stats-ID: 06JXGSQc9 - 6619038ecac1 - 20130713 X-Scanned-By: CanIt (www . roaringpenguin . com) on 172.16.100.174 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:76313 Archived-At: Thanks Greg, that sounds like good stuff in general. Sadly it's not applicable in my case -- the processing I'm doing is very much tied to the current running Emacs instance -- but it's definitely good to know those packages exist for other use cases. cheers, -Phil On 12/07/2013 01:39, Daimrod wrote: > A bit of background: > I'm GSoC student working on the XWidget branch and I wanted to add test > to it. But I've encountered two problems while trying to write "classic" > ERT tests. One is that since I'm working on the C side on an > experimental branch, sometimes Emacs crashes. The second problem is that > some tests needs to be run in a graphical Emacs. So I can't run the > tests in batch mode to circumvent the first problem. > > > I've wrote a package, emacs-parallel[1], (the API isn't very clean but > it's good enough for my current needs) to eval some stuff in another > Emacs process. I've been heavily inspired by emacs-async[2], but I've > made differents choices: > - it can start a graphical Emacs (not Batch Mode); > - it communicates through a Unix socket instead of standard I/O stream > (because, AFAIK, it is not possible to use them without Batch Mode); > - you can send data from the remote process while the process isn't > finished instead of just sending the result of the call; > - the main entry point is a function, not a macro; > - it tells you whether the process terminated normally, and if not, what > happens (exit code or signal number). > - it handles timeout (you can stop the remote instance after X seconds); > > I haven't wrote much doc yet (I've started it monday) so maybe > emacs-async is a better choice (ATM) if you don't need an graphical > Emacs or if you don't need to send data without interrupting the remote > process. > > (parallel-start (lambda () (parallel-send 42) (sleep-for 3) 12) > :post-exec (lambda (results _status) > (message "%s" results))) > > (emacs-async equivalent) > (async-start (lambda () (sleep-for 3) (list 12 42)) > (lambda (result) (message "%s" result))) > > => after 3 sec it displays (12 42) > > However, since those packages simulate parallel/async jobs with another > Emacs instance, you cannot execute code with side effects. Well, you > can, but it won't have any effect in your current Emacs instance, only > on the remote. You have to isolate the side effects and to put them in a > function to be executed once the computation (free of side effect) is > done (`finish-func' in `async-start' or `:post-exec' in > `parallel-start'). > > [1] https://github.com/daimrod/emacs-parallel.git > [2] https://github.com/jwiegley/emacs-async.git