code: def test_join_running_workers_with_exception():
      class ExpectedException(Exception):
          pass
  
      count = 0
  
      def counter():
          nonlocal count
          time.sleep(0.1)
          count += 1
          return Batch((), 0)
  
      with pytest.raises(ExpectedException):
          with spawn_workers([fake_device() for _ in range(10)]) as (
              in_queues,
              out_queues,
          ):
  
              def call_in_worker(i, f):
                  task = Task(CPUStream, compute=f, finalize=None)
                  in_queues[i].put(task)
  
              for i in range(10):
                  call_in_worker(i, counter)
  
              raise ExpectedException
  
      # There's no nondeterminism because only 1 task can be placed in input
      # queues.
      assert count == 10
  
file_path: fairscale/tests/nn/pipe/test_worker.py
imports: import threading
  import time
  import pytest
  import torch
  from fairscale.nn.pipe.microbatch import Batch
  from fairscale.nn.pipe.stream import CPUStream
  from fairscale.nn.pipe.worker import Task, spawn_workers
label_desc: Use image node_id 2 for calling a global function with example usage: test_join_running_workers_with_exception() and returns: Batch