code: def cards_for_run(
      flow_datastore,
      run_object,
      only_running,
      card_type=None,
      card_hash=None,
      card_id=None,
      max_cards=20,
  ):
      curr_idx = 0
      for step in run_object.steps():
          for task in step.tasks():
              if only_running and task.finished:
                  continue
              card_generator = cards_for_task(
                  flow_datastore,
                  task.pathspec,
                  card_type=card_type,
                  card_hash=card_hash,
                  card_id=card_id,
              )
              if card_generator is None:
                  continue
              for card in card_generator:
                  curr_idx += 1
                  if curr_idx >= max_cards:
                      raise StopIteration
                  yield task.pathspec, card
  
imports: import os
  import json
  from http.server import BaseHTTPRequestHandler
  from threading import Thread
  from multiprocessing import Pipe
  from multiprocessing.connection import Connection
  from urllib.parse import urlparse
  import time
  from .card_client import CardContainer
  from .exception import CardNotPresentException
  from .card_resolver import resolve_paths_from_task
  from metaflow.metaflow_config import DATASTORE_LOCAL_DIR
  from metaflow import namespace
  from metaflow.exception import CommandException, MetaflowNotFound, MetaflowNamespaceMismatch
label_desc: Use image node_id 2 for calling a global function with example usage: cards_for_run(flow_datastore, run_object, only_running, card_type, card_hash, card_id, max_cards) without return types