code: def make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout):
      """creates a numbered dir with a cleanup lock and removes old ones"""
      e = None
      for i in range(10):
          try:
              p = make_numbered_dir(root, prefix)
              lock_path = create_cleanup_lock(p)
              register_cleanup_lock_removal(lock_path)
          except Exception as exc:
              e = exc
          else:
              consider_lock_dead_if_created_before = (
                  p.stat().st_mtime - lock_timeout
              )
              cleanup_numbered_dir(
                  root=root,
                  prefix=prefix,
                  keep=keep,
                  consider_lock_dead_if_created_before=consider_lock_dead_if_created_before,
              )
              return p
      assert e is not None
      raise e
  
imports: from __future__ import absolute_import
  import atexit
  import errno
  import fnmatch
  import itertools
  import operator
  import os
  import shutil
  import sys
  import uuid
  import warnings
  from functools import partial
  from functools import reduce
  from os.path import expanduser
  from os.path import expandvars
  from os.path import isabs
  from os.path import sep
  from posixpath import sep
  import six
  from six.moves import map
  from .compat import PY36
  from _pytest.warning_types import PytestWarning
label_desc: Use image node_id 17 for calling a global function with example usage: make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout) and returns: p