jwiegley / emacs-async

Simple library for asynchronous processing in Emacs
GNU General Public License v3.0
838 stars 68 forks source link

Active async processes when trying to exit emacs #8

Closed mankoff closed 10 years ago

mankoff commented 12 years ago

How do I use emacs-async and not get hung processes?

I'm using emacs-async like so:

(add-hook 'after-save-hook 
  (lambda () 
    (if (or (eq major-mode 'org-mode) (eq major-mode 'org-agenda-mode))
        (dolist (file (org-mobile-files-alist))
          (if (string= (expand-file-name (car file)) (buffer-file-name))
              (fork-org-push-mobile)
              )))))

(defun fork-org-push-mobile ()
  (async-start
   `(lambda ()
           ,(async-inject-variables "org-directory\\|org-mobile-.*\\|org-agenda-files") 
      (org-mobile-push)
      )
   'ignore)
)

When I try to exit emacs, I get a warning that says:

Active processes exist; kill them an exit anyway? (y or n)

And a buffer *Process List* appears that is full of emacs-async processes like so:

emacs<13> run      *emacs*<14> /Users/mankoff/local/Applications/Org.app/Contents/MacOS/Aquamacs.bin -Q -l /Users/mankoff/local/emacs/async.el -batch -f async-batch-invoke <none>
emacs<12> run      *emacs*<13> /Users/mankoff/local/Applications/Org.app/Contents/MacOS/Aquamacs.bin -Q -l /Users/mankoff/local/emacs/async.el -batch -f async-batch-invoke <none>
emacs<11> run      *emacs*<12> /Users/mankoff/local/Applications/Org.app/Contents/MacOS/Aquamacs.bin -Q -l /Users/mankoff/local/emacs/async.el -batch -f async-batch-invoke <none>
thierryvolpiatto commented 12 years ago

Ken Mankoff notifications@github.com writes:

How do I use emacs-async and not get hung processes?

I'm using emacs-async like so:

(add-hook 'after-save-hook 
  (lambda () 
  (if (or (eq major-mode 'org-mode) (eq major-mode 'org-agenda-mode))
      (dolist (file (org-mobile-files-alist))
        (if (string= (expand-file-name (car file))
You should compare your filenames with `file-equal-p'.

(buffer-file-name)) (fork-org-push-mobile) )))))

(defun fork-org-push-mobile ()
  (async-start
   `(lambda ()
    (org-mobile-push)
    )
   'ignore)
)

The external emacs session where you are forking to execute async org-mobile-push' know nothing about this function, and all other org related vars/functions, so you should instruct this Emacs about this. For this, require the needed libraries and useasync-inject-variables'.

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

mankoff commented 12 years ago

Oops. I do inject variables. When I removed some commented lines while pasting above I cut a valid line. Between lambda and org-mobile-push I have: ,(async-inject-variables "org-directory\\|org-mobile-.*\\|org-agenda-files")

So, async-inject-variables is used. Can you give more specific advice about the other related vars-functions? How/where would I go about loading a file called my-org-mode.el? And I presume the file-equal-p comment above is an improvement but not causing this bug...

thierryvolpiatto commented 12 years ago

Ken Mankoff notifications@github.com writes:

Oops. I do inject variables. When I removed some commented lines while pasting above I cut a valid line. Between lambda and org-mobile-pushI have:,(async-inject-variables "org-directory|org-mobile-.*|org-agenda-files")` This will setq all these vars but you have to require your org stuff before (Emacs know nothing about these vars).

So, async-inject-variables is used. Can you give more specific advice about the other related vars-functions? How/where would I go about loading a file called my-org-mode.el?

async-start ;; 1) require the needed libraries ;; 2) inject vars (they will have the value that are in your current emacs)

And I presume the file-equal-p` comment above is an improvement but not causing this bug... Yes.

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

mankoff commented 12 years ago

The function I want to run asynchronously ((org-mobile-push)) does run just fine. And it runs with the top code I posted (now edited to include the inject). But often (but not always) emacs processes are still left hanging, to be discovered when I try to quit emacs.

The external async processes may or may not know certain things, but it knows enough to do what I want it to do. Unfortunately, I don't know enough how to get it to do that and then exit cleanly... Any more hints or thoughts on why it might be hanging?

mrvdb commented 12 years ago

I have a similar issue, perhaps related. I also use async.el to run a wrapped org-mobile-push. I have no process buffers left in emacs, but i noticed that leftover emacs processes exist on linux. They all look like this:

/usr/local/bin/emacs -Q -l /home/mrb/.emacs.d/el-get/async/async.el -batch -f async-batch-invoke

They are not hanging in the 'not running' sense, but looks like they are waiting on input (strace shows incomplete read(0,..)

thierryvolpiatto commented 10 years ago

I think this is fixed now, and we have anyway a notification in mode-line showing if a job is running or not. Closing, feel free to reopen.