code: def test_join_running_workers():
      count = 0
  
      def counter():
          nonlocal count
          time.sleep(0.1)
          count += 1
          return Batch((), 0)
  
      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)
  
      # There's no nondeterminism because 'spawn_workers' joins all running
      # workers.
      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 1 for calling a global function with example usage: test_join_running_workers() and returns: Batch