Closed petRUShka closed 9 years ago
I assume that latexmk causes vim to segfault, possibly due to too frequent callbacks. Check how many instances of latexmk are running at a time, e.g.
pgrep -cf "perl /usr/bin/latexmk"
There should always be only one instance of latexmk per file, but sometimes when vim crashes the latexmk instances are left behind. Starting vim again without killing latexmk first will start another latexmk instance, which then all try to compile the same file and due to conflicts cause vim to crash again, thus creating a cascading effect which would explain the high CPU usage. Killing all latexmk processes manually should help.
I had too some crashes --- never reported because I am not sure on how to reproduce them.
The common case is having two different main LaTeX files opened in two different tabs of the same gvim
window and compiling/previewing both with latexmk
; but it's not always leading to crashes.
It has happened to me as well, but I have never been able to reproduce it. And without being able to reproduce, I am also not able to debug it. I can't remember the last time it happened with me, and in my experience it is very rare.
I would be happy to investigate, but I am sorry that there is little I can do as long as I can't reproduce it... :(
There is 4 running copy of latexmk in my case!
$ pgrep -cf "perl /usr/bin/latexmk"
4
I'm thinking that it should be the reason. I'm not turning off my PC and don't logout. So may be it is some old Latexmk running and making things bad. I will check after killing all of them.
P.S. Before killing I always catch crash after several minutes of work. It was terrible!
By the way: is it possible to open VIM in debugger and see which plugin (or library) causing the crash?
On Linux, I guess I could use either fuser
or lsof
to find if there are processes that are not connected to vimtex
, and instead of starting new processes I could "reconnect". However, I have NO idea how to do this on windows.
I will investigate if I can improve the reliability. There should be some way to detect running latexmk processes. (Note that it should work regardless of file names.)
I've looked at the output of pstree and noticed that the latexmk process does not run under the vim process tree, unlike for example YCM:
systemd
├─bash -c cd '/home/lahwaacz/stuff/BAK' && max_print_line=2000 latexmk -pdf -e '$pdflatex =~ s/ / -file-line-error /' -outdir=./out/ -pvc -e '$success_cmd = "vim --servername VIMTEX --remote-expr \\"vimtex#latexmk#callback(1)\\""' -e '$failure_cmd = "vim --servername VIMTEX --remote-expr \\"vimtex#latexmk#callback(0)\\""' 'main.tex' >/tmp/vbIgaHk/17 2>&1 &
│ └─perl /usr/bin/latexmk -pdf -e $pdflatex =~ s/ / -file-line-error / -outdir=./out/ -pvc -e $success_cmd = "vim --servername VIMTEX --remote-expr \\"vimtex#latexmk#callback(1)\\"" -e $failure_cmd = "vim --servername VIMTEX --remote-expr \\"vimtex#latexmk#callback(0)\\"" main.tex
├─tinyterm
│ ├─bash
│ │ └─vim -p --servername VIMTEX header.tex main.tex chapter1.tex chapter2.tex chapter3.tex chapter4.tex references.bib
│ │ ├─python2 /usr/share/vim/vimfiles/python/ycm/../../third_party/ycmd/ycmd --port=35135 --options_file=/tmp/tmpxXYB2m --log=info --idle_suicide_seconds=10800 --stdout=/tmp/ycm_temp/server_35135_stdout.log --stderr=/tmp/ycm_temp/server_35135_stderr.log
│ │ │ └─31*[{python2}]
│ │ └─31*[{vim}]
│ └─{gmain}
...
One might think that identifying the process by its command line arguments might be enough, but this will fail if the configuration changes. As has been said in this thread, the latexmk process may have quite long life...
@lahwaacz Yes, that is because latexmk
is started in a separate shell. I am not entirely sure, but I think YCM is started with the built-in python support.
By use of pgrep -f
and /proc/PID/cwd
I've implemented a solution that I think works well on unix systems that has pgrep
available. I am not sure if it works on OSX.
I have NO idea how to do this on Windows, so I've not implemented a solution for Windows as of yet.
Note that I am not sure if the issue is completely resolved. I think the last commit should fix the main problem, though.
Actually, there must be some forking involved to detach the shell process from its parent, because the process hierarchy is preserved by default. I'm not sure yet whether this is done by vimtex, vim or the shell itself. At least on Linux it seems to be standard to kill children processes when a process dies, I think vim does it too. IMHO fixing the process tree is the proper way to go.
This is actually more a problem with vim than with vimtex. That is, vim does not allow asynchronous processes, which means that in order to run an attached external process like latexmk
, it must be run in the foreground, i.e. blocking the editor. Thus the default behaviour of vimtex is to spawn the latexmk process as a background process.
That being said, I think the current behaviour of vimtex is pretty good. I just pushed an update to the code that handles how vimtex kills latexmk when a buffer is closed. I think this should increase the robustness. See #189.
Note that neovim is getting closer to maturity. This is a project/fork of vim that will bring, among other things, asynchronicity to the vim editor. However, I have currently not begun to use neovim myself, and I have not begun to update vimtex for neovim support either.
I don't understand -- this "spawning" is done by adding an ampersand to the command, which is entirely a shell thing. But the shell itself is detached from vim with respect to the process tree.
Hmm. Perhaps I am mistaken. But I don't see how to update vimtex in order to fix things according to your suggestions.
Let's do a simple test:
ps
to get the PIDwatch pstree PID
to see the pstree for the vim instance updated every 2 seconds:call system('sleep 3')
- now the pstree will show a sleep process attached to vim:!sleep 3
; we should still see the sleep process attached:!sleep 3&
; this time the sleep process is not attached to vimI don't know how things should be, but this example at least supports my claim that for background processes, vim spawns and detaches a shell for the child process. Thus the child process no longer knows that vim is its parent. Or something like that.
If I am mistaken, and/or if there is some other way of doing this, please let me know.
I see, it's not entirely shell thing. I will surely report back if I find anything constructive.
Great, thanks!
I experience a continuously crashes with something like this appearing in terminal
or just like this
It is always happened after saving file with latex continuous mode turning on (several compilations happened also). Before crash there are a lot of refreshing of VIM and Zathura (my pdf viewer) and heavy CPU usage (according to responsiveness of system).
P.S. Arch linux, 4.0.4-2-ARCH #1 SMP PREEMPT Fri May 22 03:05:23 UTC 2015 x86_64 GNU/Linux
Xdotool
Zathura
Latexmk