From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6418 invoked by alias); 12 Jun 2018 10:24:16 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23471 Received: (qmail 11216 invoked by uid 1010); 12 Jun 2018 10:24:16 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot0-f170.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.170):SA:0(-1.9/5.0):. Processed in 1.32652 secs); 12 Jun 2018 10:24:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Vjbg54iCgxyLdY2t9yDuQr456aGBzqQVFYXBj4MwgL8=; b=IHIVJCaoRiLq34sWUVQCPSjOC8XkFRAi7dBuiOQfU2YcSDV+MKV+SIsGoc9aS0RDdv eqpcZqVIsRGj7lFiUSKK1aanxGBHJvHRQ+seolldirvqXb8plypjQJbYBoQeNFSPcqGv sld9hTjwGBzYVRWoqgaW+tpUShtc2qTjokPjmV3ESXCkkINTEOu3L2dMyVbvjcqZY+Aj GHAMxVy1n9/7R/P8hhIEIeBQ1ZP5kXrncBm3kZfBV/7Fc5C7EVthG5r/PiVq2AjkV/uC DzZwKp5bjOfNqCBli159DLZfeL3uz6/9Q2uLrxDcffiS3AWCN2Imeyf95x8vo5x85cO3 YpUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Vjbg54iCgxyLdY2t9yDuQr456aGBzqQVFYXBj4MwgL8=; b=X0Svt6+LV0azB1WpH3Ugd+zTzREjWQfePEcDmW3t3BpI+cvNOjuEZpZHSsQ694FHMi kG1uwc9u+zjUL18O6gvB+mVys1/91u29jakhurAqQonocDv4yyoRElvTk4gVTIFA2wdg S4hJCF4sLwkMeQ2/KvhKRSxBMSovRAc2AmCTbGgwJsZWfW+OWTlsgWgCuOo+9TBjP4JD BloC73EZ696d1MRzOCIDMjG2zE4VLIHBxOKq63jE7kRjL0DamJxsM8LXQlvMlRWgWUH9 IHARWvAdErjggCL6nwneOCnJWgmD258qyRx+Y/K9N0zUsUg/9ScikT1YRmKyAcXK1+6/ 42Gw== X-Gm-Message-State: APt69E3MoETGSouAWVRvTCFCGloZAiR+UNipMaQ6dx5ogn3Usc9eiaKj T6T0t2YO7khgZrAd/mlXKOmW1s2c5QQ2i0eBKtg= X-Google-Smtp-Source: ADUXVKLQnWSJPPFYUqo7sNA8fTdyMxkg22jxaR9TAbEyoTODsmmGnYdKT/ClMOBUc+noHHf6wfcqg+yf/5MbXvhcNN8= X-Received: by 2002:a9d:2c8:: with SMTP id 66-v6mr1793663otl.28.1528799052135; Tue, 12 Jun 2018 03:24:12 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Sebastian Gniazdowski Date: Tue, 12 Jun 2018 12:23:51 +0200 Message-ID: Subject: Re: Anyone familiar with auto-fu.zsh project? To: Eric Freese Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 12 June 2018 at 03:55, Eric Freese 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 ba= sh. > > 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 =E2=80=93 that <( ) process likes to survive much. I think main meth= od 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=3D0; }; } # Running, but dangerously close to idle-exit moment? if (( ZFLAI_FD !=3D 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=3D0 fi I had to do that protected race condition and request exit when close to idle exit =E2=80=93 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 > wrote: >> >> On 11 June 2018 at 10:25, Eric Freese 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 =E2=80=93 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 >> > 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 an= d >> >> it works without problems, very robust. The effect: >> >> >> >> https://asciinema.org/a/V18uHIn2BR0OVfRsmxyqkVi7K >> >> >> >> -- >> >> Best regards, >> >> Sebastian Gniazdowski >> > >> > > >