* Re: Multitasking in emacs?
2014-06-20 6:32 Multitasking in emacs? Martin
@ 2014-06-20 7:07 ` W. Greenhouse
2014-06-20 13:48 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: W. Greenhouse @ 2014-06-20 7:07 UTC (permalink / raw)
To: help-gnu-emacs-mXXj517/zsQ
Hi Martin,
Martin <kleinerdrache-RbZlAiThDcE@public.gmane.org> writes:
> Hi there,
>
> When I do a update of the packages, like
>
> M-X list-packages RET U x y
>
> or when I send large emails, emacs seems to stop me from working for the
> time this processes are running. Is there a way to put this processes
> in the background and working on in other buffers?
Emacs is usually confined to a single thread of execution and does not
[yet] have a general concept of concurrency. Instead it cleverly uses
subprocesses and asynchronous I/O to achieve concurrency-like effects in
some situations.
For talking to external subprocesses and network sockets, Emacs can use
`start-process' to make an asynchronous process, and then receive
buffered output (over pty or pipe) when it's idle, using "process
filters." Elisp programs that use `start-process' can feel almost like
they are running in multiple threads, but if Emacs needs to do a lot of
processing after receiving the subprocess results, that will block the
event loop and the user will have to wait.
There is a concurrency (multithreading as opposed to the async I/O
concept above) branch of Emacs with approximately one person working on
it. There are also some libraries to do async I/O for elisp itself (or
specific tasks in elisp), by spawning extra worker emacsen, including:
- Elnode <http://elnode.org> -- uses a herd of asynchronous Emacsen to
provide an nginx-like event-driven webserver. Currently powering the
marmalade-repo.org ELPA repo, among other things.
- async.el <https://github.com/jwiegley/emacs-async> -- simple,
general-purpose async elisp library that uses similar concepts to
elnode: a subprocess Emacs is spawned, given an execution environment
(just the vars and bindings relevant to the calculation) and told to
eval something. NB: you do have to rewrite your elisp to make use of
async.el, but one of the proof of concept setups is to allow
message-mode to send mail in a background job.
- Gnus can do some things asynchronously, by using the Agent
functionality and emacs --batch. This batch Gnus process can do things
like automatically download messages and send mail from your queue.
(info "(gnus) Batching Agents")
- org-mode can run the export functionality asynchronously in a
subprocess worker Emacs.
With the async I/O idea, there's not yet a way to just tell any
arbitrary elisp function to automatically run in a "background"
subprocess Emacs, because you need to pass it the state relevant to the
job it needs to do.
Hope that helps give you a better idea of what's happening, even if it
doesn't provide an immediate solution. But for the mail issue, perhaps
you could try async.el's smtpmail wrapper or gnus-agent-batch.
--
Best,
WGG
^ permalink raw reply [flat|nested] 3+ messages in thread