Cool, thanks! I have used this approach described in the first link you have shared:
from psutil import process_iter
from signal import SIGTERM # or SIGKILL
for proc in process_iter():
for conns in proc.connections(kind='inet'):
if conns.laddr.port == 8080:
proc.send_signal(SIGTERM) # or SIGKILL
Just needed to run the .py file with sudo in the first place, then it worked perfectly. I'll check your jupyterlab approach as well, it looks more elegant. Congrats by the way for this amazing extension and please keep up good work.