emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
622 stars 162 forks source link

ESS hangs when starting a remote julia process with tramp #138

Closed ikirill closed 9 years ago

ikirill commented 9 years ago

I was trying to start a remote julia process by asking for working directory to be /ssh:remote-server: and ESS hanged; this doesn't happen with the same remote server when running R.

Backtrace:

Debugger entered--Lisp error: (quit)
  accept-process-output(#<process julia> 0.5)
  ess-wait-for-process(#<process julia> nil 0.01)
  inferior-ess("--color=no ")
  julia(nil)

The last line of tramp's debugging output (with tramp-verbose = 6) is

02:50:51.334509 tramp-send-command (6) # cd XXX && exec  env TERMCAP\= COLUMNS\=80 EMACS\=t INSIDE_EMACS\=25.0.50.36\,comint STATATERM\=emacs PS1\=/ssh\:XXX\:\ \#\$\  julia --color\=no

The *ESS* buffer looks like this:

(julia): ess-dialect=nil, buf=*scratch*, start-arg=nil
 current-prefix-arg=nil
(inf-ess 1): lang=nil, dialect=nil, tmp-dialect=julia, buf=*scratch*
(inf-ess 1.1): procname=julia temp-dialect=julia, buf-name=*julia* 
(inf-ess 2.0) Method #2 start=nil buf=*julia*
(ess-setq-vars-LOCAL): language=julia, dialect=julia, buf=nil, comint..echoes=nil, comint..sender=inferior-ess-input-sender
(inf-ess 2.1): ess-language=julia, ess-dialect=julia buf=*julia* 
(ess-setq-vars-LOCAL): language=julia, dialect=julia, buf=nil, comint..echoes=nil, comint..sender=inferior-ess-input-sender
(i-ess 1): buf=*julia*, lang=julia, comint..echo=nil, comint..sender=inferior-ess-input-sender,
(i-ess end): buf=*julia*, lang=julia, comint..echo=nil, comint..sender=inferior-ess-input-sender,
(inf-ess 3.0): prog=julia, start-args=--color=no , echoes=nil
Making Process...Buf *julia*, :Proc julia, :Prog julia
 :Args= --color=no 
Start File=nil
(inferior-ess: waiting for process to start (before hook)

I checked that running the command directly in a shell starts the julia process, and I also checked that running R in the same way (with the same remote server) starts an R session correctly.

vspinu commented 9 years ago

I checked that running the command directly in a shell starts the julia process,

What shell? Emacs shell?

ESS is waiting for prompt from julia process. And it looks like it is not getting it. There were problems in the past with julia not working inside emacs. Make sure the remote has the most recent julia installed.

If julia works in emacs shell, there is no reason it should not work under ESS.

ikirill commented 9 years ago

What shell? Emacs shell?

Sorry, I meant that I ran it outside emacs, with iTerm2 and ssh.

ESS is waiting for prompt from julia process. And it looks like it is not getting it. There were problems in the past with julia not working inside emacs. Make sure the remote has the most recent julia installed.

Does ESS hang when it doesn't get a prompt or show an error message? What should I expect to see?

vspinu commented 9 years ago

Does ESS hang when it doesn't get a prompt or show an error message? What should I expect to see?

It hangs when julia does not show the prompt. Ssh into remote server from emacs shell or run shell through tramp. Then call invoke jullia from inside that shell. If that works then ESS should work.

I am installing julia on my server now. When it had installed I will try it myself to see if ESS works with the most recent julia.

ikirill commented 9 years ago

Running julia with ssh, starting julia by hand, then using ess-remote works fine, though.

vspinu commented 9 years ago

Ok. That's strange. Let's see if I can reproduce the problem. Still compiling.

ikirill commented 9 years ago

Maybe not relevant, but running eshell, then inside that ssh remote-server, then julia, then ess-remote, then typing "1 + 2" and hitting enter, gives me:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  comint-send-input()
  inferior-ess-send-input()
  funcall-interactively(inferior-ess-send-input)
  call-interactively(inferior-ess-send-input nil nil)
  command-execute(inferior-ess-send-input)
vspinu commented 9 years ago

Ok. I can reproduce, but I am not sure it's the same problem. After M-x julia and C-g. go to *julia* buffer and see what's there. Mine shows:

env: julia: No such file or directory

Process julia exited abnormally with code 127 at Fri Jan 16 10:44:58 2015

That is tramp cannot find julia executable.

This is what I have to fix this in my .emacs file:


(eval-after-load 'tramp-sh
  '(setq tramp-remote-path
     (append '("/home/vspinu/bin"
           "/home/churn/bin") tramp-remote-path)))
ikirill commented 9 years ago

This is exactly the right problem, I see the same *julia* buffer (I didn't notice it existed).

Do you know why tramp doesn't read .bashrc or .profile? If I ssh separately, it definitely reads the configuration files, because it can find julia executable just fine. I suppose R is just installed in some standard location.

Changing tramp-remote-path to add the path to julia doesn't seem to do anything, I added "full/path" as well as "~/path".

If I open /ssh:remote:, run M-x eshell, and then echo $PATH, I get my (local) OSX path. If I add the remote julia path to my local path (with setenv "PATH"), running M-x julia with the remote server still doesn't work.

vspinu commented 9 years ago

Changing tramp-remote-path to add the path to julia doesn't seem to do anything, I added "full/path" as well as "~/path".

Works for me. Should also work for you. Have you restarted emacs. For some reason that's needed.

vspinu commented 9 years ago

If I ssh separately, it definitely reads the configuration files, because it can find julia executable just fine.

When julia/R are invoked it's not run from a bash shell but rather directly. So your rcs are not executed. I don't know the specific details though.

ikirill commented 9 years ago

Have you restarted emacs. For some reason that's needed.

It works now, that fixed it. Thank you very much.

When julia/R are invoked it's not run from a bash shell but rather directly. So your rcs are not executed. I don't know the specific details though.

My impression is that tramp interacts with a shell (see the tramp-send-command in my first post, that is definitely a shell command), and I expected it to read at least something (I put PATH into both .bashrc and .profile just in case, and there is no .bash_profile). I also found this: https://www.gnu.org/software/emacs/manual/html_node/tramp/Remote-shell-setup.html (search for ~/.profile on that page).

vspinu commented 9 years ago

My impression is that tramp interacts with a shell (see the tramp-send-command in my first post, that is definitely a shell command), and I expected it to read at least something (I put PATH into both .bashrc and .profile just in case, and there is no .bash_profile).

Hm. That indeed makes sense. I have no idea. But it's pretty certain that .bashrc, .profile or .bash_profile are not loaded by tramp shell. I would be interested to know what's going on.

ikirill commented 9 years ago

Okay, I found this: https://www.gnu.org/software/emacs/manual/html_node/tramp/Remote-Programs.html

The right way to solve this is by doing this:

(with-eval-after-load 'tramp-sh
  (add-to-list 'tramp-remote-path 'tramp-own-remote-path))

Here tramp-own-remote-path tells tramp to load the path from remote configuration files. It's quite easy to get burned by this.

Is this a problem for ESS? I'm not sure, but since R inherits path from environment, might this be a problem for executing code remotely that invokes other executables (with system, for example)?