[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#14820: 24.3; elisp manual: How to write good idle timer worker funct
bug#14820: 24.3; elisp manual: How to write good idle timer worker functions?
Sat, 13 Jul 2013 18:38:48 +1200
Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7
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.
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, (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, 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
(parallel-start (lambda () (parallel-send 42) (sleep-for 3) 12)
:post-exec (lambda (results _status)
(message "%s" results)))
(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