code: def spawn(mode, func, *args, **kwargs):
      
      if mode is None:
          # 'threading' is the default mode.
          mode = 'threading'
      elif mode not in spawn.modes:
          # validate the given mode.
          raise ValueError('Invalid spawn mode: %s' % mode)
      if mode == 'threading':
          return spawn_thread(func, *args, **kwargs)
      elif mode == 'gevent':
          import gevent
          import gevent.monkey
          gevent.monkey.patch_select()
          gevent.monkey.patch_socket()
          return gevent.spawn(func, *args, **kwargs)
      elif mode == 'eventlet':
          import eventlet
          eventlet.patcher.monkey_patch(select=True, socket=True)
          return eventlet.spawn(func, *args, **kwargs)
      assert False
docs: Spawns a thread-like object which runs the given function concurrently.
  
      Available modes:
  
      - `threading`
      - `greenlet`
      - `eventlet`