code: def test_generator_exit_callback():
      steps = 0
      batch_size = 32
      batch_break = int(batch_size / 2)
  
      def _callback(batch_step, batch_items, batch_results):
          nonlocal steps
          # batch_items' length equals batch size by definition
          assert len(batch_items) == batch_size
          # however, we just saw mid-batch size items
          assert len(batch_results) == batch_break
          # (despite batch_size items we actually computed)
          assert (
              callback_func(batch_items)[:batch_break] == batch_results
          )
          # we break during the first batch, at mid-batch size
          assert batch_step < 1
          steps += 1
  
      m = SomeModel()
      for i, _prediction in enumerate(
          m.predict_gen(
              range(100), _callback=_callback, batch_size=batch_size
          )
      ):
          if i + 1 == batch_break:
              break
      assert steps == 1
  
file_path: modelkit/tests/test_batching.py
imports: import asyncio
  import pytest
  from modelkit.core.model import AsyncModel, Model
label_desc: Use image node_id 8 for calling a global function with example usage: test_generator_exit_callback() without return types