code: def test_threaded_nanny_events(ctx_factory):
      # https://github.com/inducer/pyopencl/issues/296
  
      import gc
      import threading
  
      def create_arrays_thread(n1=10, n2=20):
          ctx = ctx_factory()
          queue = cl.CommandQueue(ctx)
          for _i1 in range(n2):
              for _i in range(n1):
                  acl = cl.array.zeros(queue, 10, dtype=np.float32)
                  acl.get()
              # Garbage collection triggers the error
              print("collected ", str(gc.collect()))
              print("stats ", gc.get_stats())
  
      t1 = threading.Thread(target=create_arrays_thread)
      t2 = threading.Thread(target=create_arrays_thread)
  
      t1.start()
      t2.start()
  
      t1.join()
      t2.join()
  
imports: import numpy
  import numpy.linalg
  import pytest
  import pyopencl
  import pyopencl.array
  import pyopencl.cltypes
  import pyopencl.clrandom
  from pyopencl.tools import pytest_generate_tests_for_pyopencl, ImmediateAllocator, DeferredAllocator
  from pyopencl.characterize import get_pocl_version
label_desc: Use image node_id 37 for calling a global function with example usage: test_threaded_nanny_events(ctx_factory) without return types