code: def test_terminate_on_time_limit(n_iters, limit):
      started = time.time()
      trainer = Engine(_train_func)
  
      @trainer.on(Events.TERMINATE)
      def _():
          trainer.state.is_terminated = True
  
      trainer.add_event_handler(
          Events.ITERATION_COMPLETED, TimeLimit(limit)
      )
      trainer.state.is_terminated = False
  
      trainer.run(range(n_iters))
      elapsed = round(time.time() - started)
      assert elapsed <= limit + 1
      assert trainer.state.is_terminated == (n_iters > limit)
  
imports: import time
  import pytest
  from ignite.engine import Engine, Events
  from ignite.handlers import TimeLimit
label_desc: Use image node_id 3 for calling a global function with example usage: test_terminate_on_time_limit(n_iters, limit) without return types