code: def _setecho(fd, state):
      errmsg = "setecho() may not be called on this platform (it may still be possible to enable/disable echo when spawning the child process)"
  
      try:
          attr = termios.tcgetattr(fd)
      except termios.error as err:
          if err.args[0] == errno.EINVAL:
              raise IOError(
                  err.args[0], "%s: %s." % (err.args[1], errmsg)
              )
          raise
  
      if state:
          attr[3] = attr[3] | termios.ECHO
      else:
          attr[3] = attr[3] & ~termios.ECHO
  
      try:
          # I tried TCSADRAIN and TCSAFLUSH, but these were inconsistent and
          # blocked on some platforms. TCSADRAIN would probably be ideal.
          termios.tcsetattr(fd, termios.TCSANOW, attr)
      except IOError as err:
          if err.args[0] == errno.EINVAL:
              raise IOError(
                  err.args[0], "%s: %s." % (err.args[1], errmsg)
              )
          raise
  
imports: import codecs
  import errno
  import fcntl
  import io
  import os
  import pty
  import resource
  import signal
  import struct
  import sys
  import termios
  import time
  from pty import STDIN_FILENO, CHILD
  from .util import which, PtyProcessError
label_desc: Use image node_id 2 for calling a global function with example usage: _setecho(fd, state) without return types