title: ctypes asynchronous callback from other thread
body: <p>I'm trying to receive an async callback from a C thread, but Python crashes everytime such callback is... called.</p>
  <p>This is the C callback prototype:</p>
  <pre class="lang-c prettyprint-override"><code>/*! Type declaration for the frame ready callback function.
  @sa IC_SetFrameReadyCallback
  @sa IC_SetCallbacks
  @retval IC_SUCCESS Callback was set successfully
  @retval IC_ERROR An error occurred, e.g. hGrabber is NULL.*/
  typedef void (*FRAME_READY_CALLBACK)
      (HGRABBER hGrabber, unsigned char* pData, unsigned long frameNumber, void* );
  </code></pre>
  <p>And this is the C function to register the callback:</p>
  <pre class="lang-c prettyprint-override"><code>/*! Enable frame ready callback.
  @param hGrabber      Handle to a grabber object.
  @param cb Callback function of type FRAME_READY_CALLBACK
  @param x1_argument_in_void_userdata Pointer to some userdata.
  @retval IC_SUCCESS Callback was set successfully
  @retval IC_ERROR An error occurred, e.g. hGrabber is NULL.
  @sa FRAME_READY_CALLBACK*/
  int AC IC_SetFrameReadyCallback(
      HGRABBER                hGrabber,
      FRAME_READY_CALLBACK    cb,
      void*                   x1_argument_in_void_userdata);
  </code></pre>
  <p>Finally, this is part of my Python code:</p>
  <pre><code>FRAME_READY_CALLBACK = CFUNCTYPE(c_int, ICGrabber, POINTER(c_ubyte), c_ulong, c_void_p)
  
  ...
  
  library = windll.LoadLibrary('tisgrabber_x64')
  
  ...
  
  IC_SetFrameReadyCallback = library.IC_SetFrameReadyCallback
  IC_SetFrameReadyCallback.restype = c_int
  IC_SetFrameReadyCallback.argtypes = [ICGrabber, FRAME_READY_CALLBACK, c_void_p]
  
  ...
  
  def frame_ready(icGrabber, data, frameNumber, unused):
      print &quot;oh&quot;
      #print &quot;Frame&quot;, frameNumber, &quot;ready!!!&quot;
      return 1
  
  
  IC_InitLibrary(0) #library init function
  
  ...
  
  IC_SetFrameReadyCallback(hGrabber, FRAME_READY_CALLBACK(frame_ready), None)
  
  ...
  
  IC_SoftwareTrigger() #send signal
  time.sleep(2) # while sleeping, the C thread calls the.. frame_ready callback
  </code></pre>
  <p>Guess what? While sleeping, it crashes!</p>