docstr: Receive a command from Training Service.
  Returns a tuple of command (CommandType) and payload (str)
docstr_tok: ["Receive","a","command","from","Training","Service",".","Returns","a","tuple","of","command","(","CommandType",")","and","payload","(","str",")"]
code: def receive(self):
      """Receive a command from Training Service.
      Returns a tuple of command (CommandType) and payload (str)
      """
      command = None
      data = None
  
      try:
          command_content = self.receive_queue.get(False)
          if command_content is not None:
              if len(command_content) < 16:
                  # invalid header
                  nni_log(
                      LogType.Error,
                      "incorrect command is found, command must be greater than 16 bytes!",
                  )
                  return None, None
              header = command_content[:16]
              command = CommandType(header[:2])
              length = int(header[2:])
              if len(command_content) - 16 != length:
                  nni_log(
                      LogType.Error,
                      "incorrect command length, length {}, actual data length is {}, header {}.".format(
                          length, len(command_content) - 16, header
                      ),
                  )
                  return None, None
              data = command_content[16 : 16 + length]
              data = json.loads(data.decode("utf8"))
              if self.node_id is None:
                  nni_log(
                      LogType.Info,
                      "Received command, header: [%s], data: [%s]"
                      % (header, data),
                  )
              else:
                  nni_log(
                      LogType.Info,
                      "Received command(%s), header: [%s], data: [%s]"
                      % (self.node_id, header, data),
                  )
      except Empty:
          # do nothing, if no command received.
          pass
      except Exception as identifier:
          nni_log(
              LogType.Error,
              "meet unhandled exception in base_channel: %s"
              % identifier,
          )
      return command, data
  
imports: import json
  import threading
  import time
  from abc import ABC, abstractmethod
  from queue import Empty, Queue
  from .log_utils import LogType, nni_log
  from .commands import CommandType
label_desc: Use image node_id 11 for calling the BaseChannel obj's underlying member method code with example usage: obj.receive() and returns: command,  data, None,  None, None,  None