'handles queueing the task up to be sent to a worker'

def _queue_task(self, host, task, task_vars, play_context):

    display.debug(('entering    _queue_task()    for    %s/%s' % (host.name, task.action)))
    if (task.action not in action_write_locks.action_write_locks):
        display.debug(('Creating    lock    for    %s' % task.action))
        action_write_locks.action_write_locks[task.action] = Lock()
    try:
        shared_loader_obj = SharedPluginLoaderObj()
        queued = False
        starting_worker = self._cur_worker
        while True:
            (worker_prc, rslt_q) = self._workers[self._cur_worker]
            if ((worker_prc is None) or (not worker_prc.is_alive())):
                worker_prc = WorkerProcess(self._final_q, task_vars, host, task, play_context, self._loader, self._variable_manager, shared_loader_obj)
                self._workers[self._cur_worker][0] = worker_prc
                worker_prc.start()
                display.debug(('worker    is    %d    (out    of    %d    available)' % ((self._cur_worker + 1), len(self._workers))))
                queued = True
            self._cur_worker += 1
            if (self._cur_worker >= len(self._workers)):
                self._cur_worker = 0
            if queued:
                break
            elif (self._cur_worker == starting_worker):
                time.sleep(0.0001)
        self._pending_results += 1
    except (EOFError, IOError, AssertionError) as e:
        display.debug(('got    an    error    while    queuing:    %s' % e))
        return
    display.debug(('exiting    _queue_task()    for    %s/%s' % (host.name, task.action)))
