code: def get_stdin_pid(cached_result=None):
      
      if cached_result is None:
          try:
              tasks = os.listdir('/proc/self/task')
          except OSError as e:
              if e.errno != errno.ENOENT:
                  raise
              cached_result = os.getpid()
          else:
              tasks.remove(str(os.getpid()))
              assert len(tasks) == 1
              cached_result = int(tasks[0])
      return cached_result
docs: Try to get the PID of the stdin thread, otherwise get the whole process
      ID