asyncrun.vim icon indicating copy to clipboard operation
asyncrun.vim copied to clipboard

AsyncStop does not work when program does not exit normally

Open lucypero opened this issue 5 years ago • 11 comments

Also, Asyncrun believes the program is still running at some instances, for example when the program panics because of an error. AsyncStop() never works in these instances. It doesn't do anything. So I can't run the program again. I have to restart vim every time this happens.

I use it on Neovim on Windows

Example: https://github.com/skywind3000/asyncrun.vim/issues/204#issuecomment-705730506

lucypero avatar Sep 28 '20 01:09 lucypero

reproduce steps ??

skywind3000 avatar Oct 08 '20 12:10 skywind3000

Take this Odin program:

package main

main :: proc()
{
  panic("");
}

then run it with AsyncRun

:AsyncRun odin run main.odin

Even though the program just exits normally when you run it on cmd.exe, AsyncRun gets stuck and you cannot quit the program with AsyncStop and so you can't run the program again. I have to restart vim every time.

lucypero avatar Oct 08 '20 17:10 lucypero

I failed to setup an odin environment. could you provide another example in C or C++ or Python ??

My guess:

  • the process didn't actually exit.
  • the process was waiting for user input.
  • the process started another background/gui process which didn't exit.

Suggest:

  • for windows, just:

    :AsyncRun -mode=external odin run main.odin

skywind3000 avatar Oct 08 '20 19:10 skywind3000

@skywind3000

Simply running this program breaks AsyncRun.

int main(){
  return -1;
}

cl main.c /nologo

Then on vim:

:AsyncRun main

gets it stuck forever. Only fix is to restart vim. Running the same program on the console is fine.

Is there a way so that AsyncStop actually works?

lucypero avatar Feb 01 '21 21:02 lucypero

can't reproduce your error:

图片

skywind3000 avatar Feb 02 '21 04:02 skywind3000

Ok, I tested it with vim and it works. Then I tested it with Neovim with the same config and it doesn't. Maybe Neovim is the problem.

lucypero avatar Feb 02 '21 06:02 lucypero

sorry, I forgot you are using neovim and I just tested it in vim. Now, It can be reproduced after I switched to neovim:

图片

After some inspection, I found it is neovim's issue on windows, if a process returns a code below zero, neovim's job system will hang there, no further events can be received from job system's callback.

The workaround is very simple, just return something >= 0:

图片

See, successfully exited.

skywind3000 avatar Feb 02 '21 06:02 skywind3000

So keep your return code above or equal to zero. OR use a script launch.cmd to start your job:

@echo off
call %*
exit 0

This launch.cmd will override your program's return code. use it to start your program:

图片

:AsyncRun launch.cmd main

the process exited as expected. a new command modifier may help here:

let g:asyncrun_program = get(g:, 'asyncrun_program', {})
let g:asyncrun_program.fix = { opts -> 'd:\launch.cmd  ' . opts.cmd }

Then:

:AsyncRun -program=fix  main

When -program=fix is provided, the command will be modified to a new string:

图片

skywind3000 avatar Feb 02 '21 06:02 skywind3000

Unfortunately this bug still exists with the latest release from https://github.com/neovim/neovim . Has anyone opened an issue there or attempted to make a PR for it?

thePHTest avatar Sep 06 '22 05:09 thePHTest

Can this be closed ? after the new commit: https://github.com/skywind3000/asyncrun.vim/commit/a7a83c1ecdcd54636247454694ddd5d9086e3b68

skywind3000 avatar Sep 11 '22 17:09 skywind3000

I tested it on the latest version of Async and returning negative numbers no longer hangs the program.

Sharlock93 avatar Oct 15 '22 22:10 Sharlock93