code: def test_parallel_flyweights(topd=None):
      from datalad.support.gitrepo import GitRepo
  
      # ProducerConsumer relies on unique args to consumer so we will provide 2nd different arg
      def create_GitRepo(args):
          return GitRepo(args[0])
  
      # let's really hunt down race condition
      for batch in range(10):
          repopath = op.join(topd, str(batch))
          # should succeed and be the same thing
          # An example of errored run: https://github.com/datalad/datalad/issues/6598
          repos = list(
              ProducerConsumer(
                  ((repopath, i) for i in range(10)),
                  create_GitRepo,
                  jobs=10,
              )
          )
          assert op.exists(repopath)
          instances = set(map(id, repos))
          assert len(instances) == 1
  
file_path: datalad/datalad/support/tests/test_parallel.py
imports: import logging
  from functools import partial
  from time import sleep, time
  import pytest
  from datalad import lgr
  from datalad.support import path
  from datalad.support.exceptions import IncompleteResultsError
  from datalad.support.parallel import ProducerConsumer, ProducerConsumerProgressLog, no_parentds_in_futures
  from datalad.tests.utils_pytest import assert_equal, assert_greater, assert_greater_equal, assert_raises, assert_repo_status, known_failure_osx, on_osx, on_windows, rmtree, skip_if, slow, with_tempfile
label_desc: Use image node_id 8 for calling a global function with example usage: test_parallel_flyweights(topd) and returns: GitRepo