code: def test_timelimit_alarm():
      import time
      from whoosh import matching
  
      class SlowMatcher(matching.Matcher):
          def __init__(self):
              self._id = 0
  
          def id(self):
              return self._id
  
          def is_active(self):
              return self._id == 0
  
          def next(self):
              time.sleep(10)
              self._id = 1
  
          def score(self):
              return 1.0
  
      class SlowQuery(query.Query):
          def matcher(self, searcher, context=None):
              return SlowMatcher()
  
      schema = fields.Schema(text=fields.TEXT)
      ix = RamStorage().create_index(schema)
      with ix.writer() as w:
          w.add_document(text=u("Hello"))
  
      with ix.searcher() as s:
          q = SlowQuery()
  
          t = time.time()
          c = s.collector()
          c = collectors.TimeLimitCollector(c, 0.2)
          with pytest.raises(searching.TimeLimit):
              _ = s.search_with_collector(q, c)
          assert time.time() - t < 0.5
  
file_path: whoosh/tests/test_collector.py
imports: from __future__ import with_statement
  import pytest
  from whoosh import collectors, fields, query, searching
  from whoosh.compat import u, xrange
  from whoosh.filedb.filestore import RamStorage
  from whoosh.util.testing import TempIndex
label_desc: Use image node_id 4 for calling a global function with example usage: test_timelimit_alarm() and returns: self, unknown, int, SlowMatcher