rofunc.utils.oslab.internet
#
1. Module Contents#
1.1. Functions#
Get the port with |
|
Reserve an available TCP port to listen on. |
1.2. API#
- rofunc.utils.oslab.internet.get_so_reuseport()[source]#
Get the port with
SO_REUSEPORT
flag set.- Returns:
port number or None
- rofunc.utils.oslab.internet.reserve_sock_addr()[source]#
Reserve an available TCP port to listen on.
The reservation is done by binding a TCP socket to port 0 with
SO_REUSEPORT
flag set (requires Linux >=3.9). The socket is then kept open until the generator is closed.To reduce probability of ‘hijacking’ port, socket should stay open and should be closed _just before_ starting of
tf.train.Server
Example:
>>> import os >>> from tensorboard import program >>> from rofunc.utils.oslab.internet import reserve_sock_addr >>> tb = program.TensorBoard() >>> # Find a free port >>> with reserve_sock_addr() as (h, p): ... argv = ['tensorboard', f"--logdir={os.getcwd()}", f"--port={p}"] ... tb_extra_args = os.getenv('TB_EXTRA_ARGS', "") ... if tb_extra_args: ... argv += tb_extra_args.split(' ') ... tb.configure(argv) >>> # Launch TensorBoard >>> url = tb.launch()