class_docstr: A WebSocket connection.
  
  Call :meth:`connect` before :meth:`send` and :meth:`receive`.
  
  All methods are thread safe.
  
  Parameters
  ----------
  url
      The WebSocket URL.
      For tuner command channel it should be something like ``ws://localhost:8080/tuner``.
class_docstr_tok: ["A","WebSocket","connection",".","Call",":","meth",":","`","connect","`","before",":","meth",":","`","send","`","and",":","meth",":","`","receive","`",".","All","methods","are","thread","safe",".","Parameters","--","--","--","--","--","url","The","WebSocket","URL",".","For","tuner","command","channel","it","should","be","something","like","``","ws",":","\/\/localhost:8080\/tuner","``","."]
code: def connect(self) -> None:
      global _event_loop, _event_loop_refcnt
      with _event_loop_lock:
          _event_loop_refcnt += 1
          if _event_loop is None:
              _logger.debug("Starting event loop.")
              # following line must be outside _run_event_loop
              # because _wait() might be executed before first line of the child thread
              _event_loop = asyncio.new_event_loop()
              thread = Thread(
                  target=_run_event_loop,
                  name="NNI-WebSocketEventLoop",
                  daemon=True,
              )
              thread.start()
  
      _logger.debug(f"Connecting to {self._url}")
      self._ws = _wait(_connect_async(self._url))
      _logger.debug(f"Connected.")
  
file_path: nni/nni/runtime/command_channel/websocket/connection.py
imports: from __future__ import annotations
  import asyncio
  import logging
  from threading import Lock, Thread
  from typing import Any, Type
  import websockets
  import nni
  from ..base import Command
label_desc: Use image node_id 2 for calling the WsConnection obj's underlying member method code with example usage: obj.connect() without return types