code: def is_port_in_use(port: int) -> bool:
      """Checks if the given port is in use."""
      with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
          return s.connect_ex(("localhost", port)) == 0
  
file_path: pytorch-lightning/src/lightning/app/utilities/port.py
imports: import os
  import socket
  from typing import Optional
  from lightning_cloud.openapi import AppinstancesIdBody, Externalv1LightningappInstance, V1NetworkConfig
  from lightning.app.utilities.network import LightningClient, find_free_network_port
label_desc: Use image node_id 1 for calling a global function with example usage: is_port_in_use(port) and returns: unknown