code: def bind_to_random_port(sock, addr_base, max_tries=100, nng=True):
      num_tries = 0
      while num_tries < max_tries:
          try:
              port = random.randint(MIN_PORT, MAX_PORT)
              addr = "{}:{}".format(addr_base, port)
              if nng:
                  sock.listen(addr)
              else:
                  sock.bind(addr)
              return port
          except:
              num_tries += 1
              continue
  
      return
  
imports: import random
  import logging
  import multiprocessing
  import threading
  from fiber.backend import get_backend
label_desc: Use image node_id 2 for calling a global function with example usage: bind_to_random_port(sock, addr_base, max_tries, nng) and returns: port