docs: def dynamic_exclusion_worker(display, n_threads):
      """This worker allows mutualy exclusive jobs to start safely. The
      user provides the information on which jobs exclude the simultaneous
      execution of other jobs::
  
          a = task()
          b = task()
  
          update_hints(a, {'task': '1', 'exclude': ['2']})
          update_hints(b, {'task': '2', 'exclude': ['1']})
  
          run(gather(a, b))
  
      Using this worker, when task ``a`` is sent to the underlying worker,
      task ``b`` is blocked until ``a`` completes, and vice versa.
      """
  
      LogQ = Queue()
  
      threading.Thread(
          target=patch,
          args=(LogQ.source, sink_map(display)),
          daemon=True).start()
  
      W = Queue() \
          >> branch(log_job_start >> LogQ.sink) \
          >> thread_pool(*repeat(worker, n_threads)) \
          >> branch(LogQ.sink)
  
      result_source, job_sink = W.setup()
  
      jobs = {}
      key_task = {}
  
      @push
      def pass_job():
          """The scheduler sends jobs to this coroutine. If the 'exclude' key is
          found in the hints, it is run in exclusive mode. We keep an internal
          record of these jobs, and whether they are 'waiting', 'running' or
          'done'.  """
          while True:
              key, job = yield
  
              if job.hints and 'exclude' in job.hints:
                  j = Job(task=job.hints['task'],
                          exclude=job.hints['exclude'],
                          state='waiting',
                          job=job,
                          key=key)
                  jobs[j.task] = j
                  key_task[key] = j.task
                  try_to_start(j.task)
  
              else:
                  job_sink.send((key, job))
  
      def is_not_running(task):
          """Checks if a task is not running."""
          return not (task in jobs and jobs[task].state == 'running')
  
      def try_to_start(task):
          """Try to start a task. This only succeeds if the task hasn't already
          run, and no jobs are currently running that is excluded by the task."""
          if jobs[task].state != 'waiting':
              return
  
          if all(is_not_running(i) for i in jobs[task].exclude):
              jobs[task].state = 'running'
              key, job = jobs[task].key, jobs[task].job
              job_sink.send((key, job))
  
      def finish(key):
          """Finish a job. This function is called when we recieve a result."""
          task = key_task[key]
          jobs[task].state = 'done'
          for i in jobs[task].exclude:
              try_to_start(i)
  
      def pass_result():
          """Recieve a result; finish the task in the register and send the result
          back to the scheduler."""
          for key, status, result, err in result_source:
              if key in key_task:
                  finish(key)
  
              yield (key, status, result, err)
  
      return Connection(pass_result, pass_job)