code: def _q2q_batch(
      func,
      queue_in,
      queue_out,
      filterf=lambda x: x is not None,
      batch_size=32,
      timeout=1,
  ):
      while True:
          added = 0
          batch = []
          while True:
              try:
                  if added > 0:
                      next_el = queue_in.get_nowait()
                  else:
                      next_el = queue_in.get(True, timeout)
  
                  if filterf(next_el):
                      batch.append(next_el)
                      added += 1
  
                  if added == batch_size:
                      break
              except Empty:
                  break
  
          if not any(batch):
              return
  
          retval = func(batch)
  
          for el in retval:
              put_success = False
              while not put_success:
                  try:
                      queue_out.put_nowait(el)
                      put_success = True
                  except Full:
                      pass
  
imports: import types
  from studio.util import logs
  from PIL import Image
  from threading import Thread
  import numpy
  import itertools
  import six
label_desc: Use image node_id 2 for calling a global function with example usage: _q2q_batch(func, queue_in, queue_out, filterf, batch_size, timeout) without return types