code: def test_event_set_callback(ctx_factory):
      import sys
  
      if sys.platform.startswith("win"):
          pytest.xfail("Event.set_callback not present on Windows")
  
      ctx = ctx_factory()
      queue = cl.CommandQueue(ctx)
  
      _xfail_if_pocl_gpu(queue.device, "event callbacks")
  
      if ctx._get_cl_version() < (1, 1):
          pytest.skip("OpenCL 1.1 or newer required for set_callback")
  
      rng = np.random.default_rng(seed=42)
      a_np = rng.random(50000, dtype=np.float32)
      b_np = rng.random(50000, dtype=np.float32)
  
      got_called = []
  
      def cb(status):
          got_called.append(status)
  
      mf = cl.mem_flags
      a_g = cl.Buffer(
          ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a_np
      )
      b_g = cl.Buffer(
          ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b_np
      )
  
      prg = cl.Program(
          ctx,
          """
      __kernel void sum(__global const float *a_g, __global const float *b_g,
          __global float *res_g) {
        int gid = get_global_id(0);
        res_g[gid] = a_g[gid] + b_g[gid];
      }
      """,
      ).build()
  
      res_g = cl.Buffer(ctx, mf.WRITE_ONLY, a_np.nbytes)
  
      uevt = cl.UserEvent(ctx)
  
      evt = prg.sum(
          queue, a_np.shape, None, a_g, b_g, res_g, wait_for=[uevt]
      )
  
      evt.set_callback(cl.command_execution_status.COMPLETE, cb)
  
      uevt.set_status(cl.command_execution_status.COMPLETE)
  
      queue.finish()
  
      counter = 0
  
      # yuck
      while not got_called:
          from time import sleep
  
          sleep(0.01)
  
          # wait up to five seconds (?!)
          counter += 1
          if counter >= 500:
              break
  
      assert got_called
  
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 28 for calling a global function with example usage: test_event_set_callback(ctx_factory) without return types