QuantEcon / meta

For issues and discussion covering more than one repository
0 stars 0 forks source link

[server] port requests when multiple users of a server #95

Open mmcky opened 1 year ago

mmcky commented 1 year ago

@chappiewuzefan any thoughts on this would be great

If another user is logged into the server and uses --port=8080 for port redirection then this causes port collisions if another user tries to request the same port.

We could either:

  1. check which ports are in use and request another (and document how to do this in the manual)
  2. everyone uses different port ranges
  3. find a different approach that is automatic to access jupyter-lab.
chappiewuzefan commented 1 year ago

for 3:

from subprocess import Popen

def find_free_port():
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind(('', 0))
        return s.getsockname()[1]

free_port = find_free_port()
print(f"Starting Jupyter Lab on port {free_port}")
Popen(["jupyter", "lab", f"--port={free_port}"])
python3 start_jupyter.py

todo:

  1. need test this code