zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Eric Freese <ericdfreese@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Anyone familiar with auto-fu.zsh project?
Date: Tue, 12 Jun 2018 12:23:51 +0200	[thread overview]
Message-ID: <CAKc7PVDFLmcRYQBM0-0xMwcCRNmqQm4+G7gcfJAhiMZzTzbJcA@mail.gmail.com> (raw)
In-Reply-To: <CAAikoA+93yDK4F-=ogf8HpheVeLG59LeeHGEgk4dCURoGhFZfw@mail.gmail.com>

On 12 June 2018 at 03:55, Eric Freese <ericdfreese@gmail.com> wrote:
> Do you know if there is any way to get the PID of the process spawned for
> process substitution? It looks like `$!` doesn't hold it as it does in bash.
>
> Ideally I could kill these child processes when they're no longer needed so
> that long-running ones don't tie up resources unnecessarily.

I recall very weakly that this appeared for a moment when writing the
logger – that <( ) process likes to survive much. I think main method
is that the spawned function exits. But you seem to want both short
running processes that exit by themselves and long running processes,
that do not exit. My logger exits after configurable amount of
seconds, like 20 of not receiving new logs (I have opposite pipe
direction) or when not log but special exit-string is written to the
named pipe. Found the code:

# Cannot write newline (newline alone is ignored, not logged)? Then cleanup
(( $ZFLAI_FD )) && { builtin print -r -u$ZFLAI_FD 2>&$ZFLAI_NULL_FD ||
{ builtin exec {ZFLAI_FD}>&-; ZFLAI_FD=0; }; }

# Running, but dangerously close to idle-exit moment?
if (( ZFLAI_FD != 0 && ZFLAI_LAST_ACTION + ZFLAI_KEEP_ALIVE - 10 <
EPOCHSECONDS )); then
    builtin print -u$ZFLAI_FD '!ZFLAI-SPECIAL-CMD: exit' 2>/dev/null
    builtin exec {ZFLAI_FD}>&-
    ZFLAI_FD=0
fi

I had to do that protected race condition and request exit when close
to idle exit – this way it is certain that the following, actual
message will not be written during the short window between checking
that <( ) process is alive, and the process being in state of exiting
during that check.

Maybe this will suggest something. I'm busy and cannot switch to other
project right now, I probably will have time tomorrow, so I can fiddle
with this and maybe find something for opposite pipe direction. Maybe
someone knows a trick to open bidirectional named pipe(s) for <( )?
Exec can do {FD}<> <(...), can't remember if I checked this, but
rather yes, checked now and it seems to not work.

Maybe this: long-running process outputs message "EXIT?" every 5
seconds. When write to stdout fails, then exit. But named pipes are
quite distinct, not sure if the write will fail after doing exec
{FD}<&- done on the client, interactive side.

> On Mon, Jun 11, 2018 at 3:46 AM, Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
>>
>> On 11 June 2018 at 10:25, Eric Freese <ericdfreese@gmail.com> wrote:
>> > Wow this is much nicer. I've implemented on `develop` branch of
>> > zsh-autosuggestions.
>>
>> Decided to do the testing, it's just checkout of develop branch and
>> then normal everyday use. First impression was that suggestions appear
>> very quickly, faster than with zpty.
>>
>> > Thank you!
>>
>> n/p, I use this in unpublished logger. Background process is started
>> on demand with <( ), which happens when someone logs something with
>> zflai-log. It stores to SQLite, MySQL, ElasticSearch, plain file. All
>> works without any problems, and logging into <( ) spawned process has
>> negligible duration, that's the point – someone wants MySQL logs but
>> do not want slowdown.
>>
>> > Eric Freese
>> > 303 875 2359
>> >
>> > On Sun, Jun 10, 2018 at 11:24 PM, Sebastian Gniazdowski
>> > <sgniazdowski@gmail.com> wrote:
>> >>
>> >> Hello,
>> >> I've just implemented async feature without using zpty. From what I
>> >> saw zsh-autosuggestions uses zpty to look-up the suggestion. Maybe it
>> >> has some drawbacks and you would be interested in using <( ) instead
>> >> of zpty (it's probably still required to capture completions, though)?
>> >> It's similar to using zpty:
>> >>
>> >> exec {PCFD}< <(-fast-highlight-check-path)
>> >> zle -F -w "$PCFD" fast-highlight-check-path-handler
>> >>
>> >> -fast-highlight-check-path-handler() {
>> >>     if read -r -u "$PCFD" line; then
>> >>     ...
>> >>     fi
>> >>     zle -F ${PCFD}
>> >>     exec {PCFD}<&-
>> >> }
>> >>
>> >> <( ) process is automatically disowned, I've used it in 2 projects and
>> >> it works without problems, very robust. The effect:
>> >>
>> >> https://asciinema.org/a/V18uHIn2BR0OVfRsmxyqkVi7K
>> >>
>> >> --
>> >> Best regards,
>> >> Sebastian Gniazdowski
>> >
>> >
>
>


  reply	other threads:[~2018-06-12 10:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-06 17:42 Sebastian Gniazdowski
2018-06-06 18:35 ` Eric Freese
2018-06-09 15:30   ` Sebastian Gniazdowski
2018-06-10  0:58     ` Eric Freese
2018-06-11  5:24       ` Sebastian Gniazdowski
2018-06-11  8:25         ` Eric Freese
2018-06-11  9:46           ` Sebastian Gniazdowski
2018-06-12  1:55             ` Eric Freese
2018-06-12 10:23               ` Sebastian Gniazdowski [this message]
2018-06-12 11:32               ` Peter Stephenson
2018-06-13  4:09                 ` Eric Freese
2018-06-13  7:26                   ` dana
2018-06-13  7:32                     ` Sebastian Gniazdowski
2018-06-13  8:28                       ` Sebastian Gniazdowski
2018-06-13  9:17                         ` dana
2018-06-13 10:48                           ` Sebastian Gniazdowski
2018-06-13 11:43                             ` dana
2018-06-14  8:55                           ` Peter Stephenson
2018-06-14  9:48                             ` dana
2018-06-14 10:00                               ` Peter Stephenson
2018-06-13  7:27                   ` Sebastian Gniazdowski
2018-06-06 23:45 ` Takeshi Banse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKc7PVDFLmcRYQBM0-0xMwcCRNmqQm4+G7gcfJAhiMZzTzbJcA@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=ericdfreese@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).