Understanding job_start()

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Understanding job_start()

Nicola
Some time ago I had defined a thin wrapper around job_start() to run a LaTeX
job asynchronously. Recently, it has stopped working. For some reason, with Vim
7.4.1817, when I give the following command:

call job_start(['lualatex', 'foo.tex'])

the job is not started any longer (or, if it is, it dies immediately).
Suspecting some problem with I/O redirection, I have tried to set "out_io" and
"err_io". If I use:

call job_start(['lualatex', 'foo.tex'],
  \ {"out_io": "null", "err_io": "null"})

the job is started, but the screen gets garbled with the output from lualatex,
and I need to :redraw! the screen. On the other hand, the following works just
fine, i.e., it silently runs lualatex in the background as I want:

call job_start(['lualatex', 'foo.tex'],
  \ {"out_io": "file", "out_name": "/dev/null", "err_io": "null"})

Shouldn't this form be equivalent to the previous one? In general, if all I
want is launch a process, but I don't care about its output, is this the right
way?

Tangentially related to the above, it seems to me that the callback is not
called as soon as the job is done, but only after a while, and it's triggered
only if I press some key. Is that normal?

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Nicola
On 2016-05-06 17:19:58 +0000, Nicola said:

> Some time ago I had defined a thin wrapper around job_start() to run a LaTeX
> job asynchronously. Recently, it has stopped working. For some reason, with Vim
> 7.4.1817, when I give the following command:
>
> call job_start(['lualatex', 'foo.tex'])
>
> the job is not started any longer (or, if it is, it dies immediately).
> Suspecting some problem with I/O redirection, I have tried to set "out_io" and
> "err_io". If I use:
>
> call job_start(['lualatex', 'foo.tex'],
>   \ {"out_io": "null", "err_io": "null"})
>
> the job is started, but the screen gets garbled with the output from lualatex,
> and I need to :redraw! the screen.

To be clear, the above also happens if I close "in_io", too, as
explained in the
manual. And I've tried to add redirection in the command, too:

    call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
    \ {"in_io": "null", "out_io": "null", "err_io": "null"})

This still fills the screen with the output from lualatex.

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Bram Moolenaar

Nicola wrote:

> On 2016-05-06 17:19:58 +0000, Nicola said:
>
> > Some time ago I had defined a thin wrapper around job_start() to run a LaTeX
> > job asynchronously. Recently, it has stopped working. For some reason, with Vim
> > 7.4.1817, when I give the following command:
> >
> > call job_start(['lualatex', 'foo.tex'])
> >
> > the job is not started any longer (or, if it is, it dies immediately).
> > Suspecting some problem with I/O redirection, I have tried to set "out_io" and
> > "err_io". If I use:
> >
> > call job_start(['lualatex', 'foo.tex'],
> >   \ {"out_io": "null", "err_io": "null"})
> >
> > the job is started, but the screen gets garbled with the output from lualatex,
> > and I need to :redraw! the screen.
>
> To be clear, the above also happens if I close "in_io", too, as
> explained in the
> manual. And I've tried to add redirection in the command, too:
>
>     call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
>     \ {"in_io": "null", "out_io": "null", "err_io": "null"})
>
> This still fills the screen with the output from lualatex.

What system is this on?  What patch level?

Vim should redirect the outputs, but this may only work on Unix.
It appears on Windows it just skips creatting the pipes, but doesn't
connected them to /dev/null (if such a thing exists on Windows).

You mention a callback, but your code doesn't show any callback.
If you mean the exit_cb for the job, that is indeed called after some
delay.  You can speed it up by calling job_status(), e.g. in the channel
close callback.

--
Corn oil comes from corn and olive oil comes from olives, so where
does baby oil come from?

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Nicola
On 2016-05-06 21:23:30 +0000, Bram Moolenaar said:

> Nicola wrote:
>
>> On 2016-05-06 17:19:58 +0000, Nicola said:
>>
>>> Some time ago I had defined a thin wrapper around job_start() to run a LaTeX
>>> job asynchronously. Recently, it has stopped working. For some reason, with Vim
>>> 7.4.1817, when I give the following command:
>>>
>>> call job_start(['lualatex', 'foo.tex'])
>>>
>>> the job is not started any longer (or, if it is, it dies immediately).
>>> Suspecting some problem with I/O redirection, I have tried to set "out_io" and
>>> "err_io". If I use:
>>>
>>> call job_start(['lualatex', 'foo.tex'],
>>> \ {"out_io": "null", "err_io": "null"})
>>>
>>> the job is started, but the screen gets garbled with the output from lualatex,
>>> and I need to :redraw! the screen.
>>
>> To be clear, the above also happens if I close "in_io", too, as
>> explained in the
>> manual. And I've tried to add redirection in the command, too:
>>
>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
>>
>> This still fills the screen with the output from lualatex.
>
> What system is this on?  What patch level?

OS X, Vim 7.4.1817 from Homebrew, compiled --with-lua --with-luajit.

If someone with a TeX installation wants to try to reproduce, this is
the code I am using:

  fun! lf_shell#async_run(cmd, ...)
    let l:callback = a:0 > 0 ? a:1 : 'lf_shell#callback'
    call job_start(a:cmd, {"exit_cb": l:callback, "in_io": "null",
"out_io": "null",  "err_io": "null"})
  endf

  fun! lf_shell#callback(job, status)
    if a:status == 0
      echo "Success!"
    else
      echo "Job failed."
    endif
  endf

let g:latexmk = split('latexmk -lualatex -cd -pv- -synctex=1
-file-line-error -interaction=nonstopmode')

command! -nargs=0 LuaLaTeX echo "Typesetting..."<bar>
      \ call lf_shell#async_run(g:latexmk+[expand('%:p')])

> You mention a callback, but your code doesn't show any callback.
> If you mean the exit_cb for the job, that is indeed called after some
> delay.  You can speed it up by calling job_status(), e.g. in the channel
> close callback.

Ah, ok. As you see from the code above, I indeed use exit_cb. I will change my
code to keep track of the job status as you suggest (currently, I am discarding
job_start()'s return value).

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Nicola
On 2016-05-07 07:04:44 +0000, Nicola said:
>>>
>>>
>>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
>>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
>>>
>>> This still fills the screen with the output from lualatex.

Minimal example:

vim -u NONE
:call job_start(['echo','hello'],{"out_io":"null"})

This prints 'hello' in the top-left corner of the screen.

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Nicola
On 2016-05-07 10:28:43 +0000, Nicola said:

> On 2016-05-07 07:04:44 +0000, Nicola said:
>>>>
>>>>
>>>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
>>>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
>>>>
>>>> This still fills the screen with the output from lualatex.
>
> Minimal example:
>
> vim -u NONE
> :call job_start(['echo','hello'],{"out_io":"null"})
>
> This prints 'hello' in the top-left corner of the screen.

Likely related: I cannot send the output to a buffer either. When I try:

:call job_start(['echo', 'hello'], {"out_io": "buffer", "out_name": ""})

the new buffer contains only one line:

Reading from channel output...

But 'hello' is not appended. I have also tried to explicitly set "mode"
to "nl" or "raw", but the result is the same. Ditto for "err_io":"buffer".

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Bram Moolenaar
In reply to this post by Nicola

Nicola wrote:

> On 2016-05-07 07:04:44 +0000, Nicola said:
> >>>
> >>>
> >>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
> >>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
> >>>
> >>> This still fills the screen with the output from lualatex.
>
> Minimal example:
>
> vim -u NONE
> :call job_start(['echo','hello'],{"out_io":"null"})
>
> This prints 'hello' in the top-left corner of the screen.

Surprisingly I can reproduce this.  Will have to find out what goes
wrong, I thought this was working.

I also see the job with "defunc" status.

--
Did Adam and Eve have navels?

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Nicola
On 2016-05-07 14:21:15 +0000, Bram Moolenaar said:

> Nicola wrote:
>
>> On 2016-05-07 07:04:44 +0000, Nicola said:
>>>>>
>>>>>
>>>>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
>>>>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
>>>>>
>>>>> This still fills the screen with the output from lualatex.
>>
>> Minimal example:
>>
>> vim -u NONE
>> :call job_start(['echo','hello'],{"out_io":"null"})
>>
>> This prints 'hello' in the top-left corner of the screen.
>
> Surprisingly I can reproduce this.  Will have to find out what goes
> wrong, I thought this was working.
>
> I also see the job with "defunc" status.

I have just tried patch 1824 and I confirm that this is solved. Thanks!

Re:

> I cannot send the output to a buffer either. When I try:
>
> :call job_start(['echo', 'hello'], {"out_io": "buffer", "out_name": ""})
>
> the new buffer contains only one line:
>
> Reading from channel output...
>
> But 'hello' is not appended. I have also tried to explicitly set "mode"
> to "nl" or "raw", but the result is the same. Ditto for "err_io":"buffer".

This still behaves the same. Am I misunderstanding how this feature is meant
to be used?

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Nicola
On 2016-05-08 15:30:01 +0000, Nicola said:

> On 2016-05-07 14:21:15 +0000, Bram Moolenaar said:
>
>> Nicola wrote:
>>
>>> On 2016-05-07 07:04:44 +0000, Nicola said:
>>>>>>
>>>>>>
>>>>>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
>>>>>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
>>>>>>
>>>>>> This still fills the screen with the output from lualatex.
>>>
>>> Minimal example:
>>>
>>> vim -u NONE
>>> :call job_start(['echo','hello'],{"out_io":"null"})
>>>
>>> This prints 'hello' in the top-left corner of the screen.
>>
>> Surprisingly I can reproduce this.  Will have to find out what goes
>> wrong, I thought this was working.
>>
>> I also see the job with "defunc" status.
>
> I have just tried patch 1824 and I confirm that this is solved. Thanks!
>
> Re:
>
>> I cannot send the output to a buffer either. When I try:
>>
>> :call job_start(['echo', 'hello'], {"out_io": "buffer", "out_name": ""})
>>
>> the new buffer contains only one line:
>>
>> Reading from channel output...
>>
>> But 'hello' is not appended. I have also tried to explicitly set "mode"
>> to "nl" or "raw", but the result is the same. Ditto for "err_io":"buffer".
>
> This still behaves the same. Am I misunderstanding how this feature is meant
> to be used?

I can make it work by adding an empty callback:

fun! MyCallback(channel, msg)
endf

call job_start(['echo', 'hello'], {"out_io": "buffer", "out_name": "",
"out_cb": "MyCallback"})

Is a callback really mandatory when out_io is "buffer", or is it a bug? The
manual says that out_cb is "Only for when the channel uses pipes", which I
interpret as "only when out_io is set to 'pipe'", but maybe I am wrong.

Also, is there a way to suppress the "Reading from channel output..." line?

Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Bram Moolenaar
In reply to this post by Nicola

Nicola wrote:

> >> On 2016-05-07 07:04:44 +0000, Nicola said:
> >>>>>
> >>>>>
> >>>>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
> >>>>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
> >>>>>
> >>>>> This still fills the screen with the output from lualatex.
> >>
> >> Minimal example:
> >>
> >> vim -u NONE
> >> :call job_start(['echo','hello'],{"out_io":"null"})
> >>
> >> This prints 'hello' in the top-left corner of the screen.
> >
> > Surprisingly I can reproduce this.  Will have to find out what goes
> > wrong, I thought this was working.
> >
> > I also see the job with "defunc" status.
>
> I have just tried patch 1824 and I confirm that this is solved. Thanks!
>
> Re:
>
> > I cannot send the output to a buffer either. When I try:
> >
> > :call job_start(['echo', 'hello'], {"out_io": "buffer", "out_name": ""})
> >
> > the new buffer contains only one line:
> >
> > Reading from channel output...
> >
> > But 'hello' is not appended. I have also tried to explicitly set "mode"
> > to "nl" or "raw", but the result is the same. Ditto for "err_io":"buffer".
>
> This still behaves the same. Am I misunderstanding how this feature is meant
> to be used?

Somehow the test for this passes, but your example fails.  Try the next
patch.

--
We apologise again for the fault in the subtitles.  Those responsible for
sacking the people who have just been sacked have been sacked.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Understanding job_start()

Nicola
On 2016-05-08 19:49:01 +0000, Bram Moolenaar said:

> Nicola wrote:
>
>>>> On 2016-05-07 07:04:44 +0000, Nicola said:
>>>>>>>
>>>>>>>
>>>>>>> call job_start(['lualatex', 'foo.tex', '>/dev/null', '2>&1'],
>>>>>>> \ {"in_io": "null", "out_io": "null", "err_io": "null"})
>>>>>>>
>>>>>>> This still fills the screen with the output from lualatex.
>>>>
>>>> Minimal example:
>>>>
>>>> vim -u NONE
>>>> :call job_start(['echo','hello'],{"out_io":"null"})
>>>>
>>>> This prints 'hello' in the top-left corner of the screen.
>>>
>>> Surprisingly I can reproduce this.  Will have to find out what goes
>>> wrong, I thought this was working.
>>>
>>> I also see the job with "defunc" status.
>>
>> I have just tried patch 1824 and I confirm that this is solved. Thanks!
>>
>> Re:
>>
>>> I cannot send the output to a buffer either. When I try:
>>>
>>> :call job_start(['echo', 'hello'], {"out_io": "buffer", "out_name": ""})
>>>
>>> the new buffer contains only one line:
>>>
>>> Reading from channel output...
>>>
>>> But 'hello' is not appended. I have also tried to explicitly set "mode"
>>> to "nl" or "raw", but the result is the same. Ditto for "err_io":"buffer".
>>
>> This still behaves the same. Am I misunderstanding how this feature is meant
>> to be used?
>
> Somehow the test for this passes, but your example fails.  Try the next
> patch.

Fixed. Thanks a lot!
Nicola


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.