help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multitasking in emacs?


From: W . Greenhouse
Subject: Re: Multitasking in emacs?
Date: Fri, 20 Jun 2014 07:07:45 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Hi Martin,

Martin <kleinerdrache@gmx.at> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]