You are not logged in.
Hi everyone, I created a .desktop file so I can start jupyter-lab from my application launcher (fuzzel). Everything launches correctly, opens a firefox tab, connects to the jupyter server, etc, but when I close the tab, the server is still running in the background.
If I launched jupyter-lab from terminal, I could just control-C, but from desktop it's mildly annoying to leave a process running unless I open up a terminal to kill it manually. When running from terminal, I can see that closing a tab logs `Starting buffering for` and then the python kernel number. My plan is to somehow read the stdout from jupyter and when I see `Starting buffering`, pkill jupyter-lab.
I tried to pipe
jupyter-lab | grep "Starting buffering for"(in terminal) with the idea of feeding that into a conditional statement. I just got the same output as before and upon exiting got a broken pipe error, because it's still executing the jupyter command and hasn't gotten to the grep command.
Another idea is to write the output to a temporary text file, and simulataneously launch a helper script to read that text file until the keyword shows up, but that feels a little clunky. Is there a better way to accomplish this goal or some tool or function I'm forgetting about/don't know about? Thanks!
Last edited by horseBattery (2026-01-06 15:55:34)
Offline
That's not gonna work for a plethora of reasons (well, sorta)
1. The error will most likely go to stdout
2. if you don't limit the grep it will never exit (as long as the jupyter-lab process runs
3. you need to tell grep to run stuff line-buffered
Synthetic demo:
( i=0; while true; do echo $((++i)) >&2; sleep 1; done) 2>&1 1>/dev/null | grep -m1 --line-buffered 5 && echo fooYour case:
jupyter-lab 2>&1 1>/dev/null | grep -m1 --line-buffered "Starting buffering for" && echo foo"2>&1 1>/dev/null" sends stdout into the nirwana and stderr into stdout
-m1 waits for the first match only
--line-buffered makes grep read the stdin line-by-line
An alternative approach would be
while read line; do [[ "$line" =~ "Starting buffering for" ]] && pkill jupyter-lab; done < <(jupyter-lab 2>&1 1>/dev/null)=~ matches regular expressions, you can use
"$line" = *"Starting buffering for"*if you don't need that.
Offline
Thanks Seth, the 'while read line do [...]' worked perfectly. Appreciate the help!
Offline