Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

55 lignes
1.5 KiB

  1. @cython.no_gc_clear
  2. cdef class UVAsync(UVHandle):
  3. cdef _init(self, Loop loop, method_t callback, object ctx):
  4. cdef int err
  5. self._start_init(loop)
  6. self._handle = <uv.uv_handle_t*>PyMem_RawMalloc(sizeof(uv.uv_async_t))
  7. if self._handle is NULL:
  8. self._abort_init()
  9. raise MemoryError()
  10. err = uv.uv_async_init(self._loop.uvloop,
  11. <uv.uv_async_t*>self._handle,
  12. __uvasync_callback)
  13. if err < 0:
  14. self._abort_init()
  15. raise convert_error(err)
  16. self._finish_init()
  17. self.callback = callback
  18. self.ctx = ctx
  19. cdef send(self):
  20. cdef int err
  21. self._ensure_alive()
  22. err = uv.uv_async_send(<uv.uv_async_t*>self._handle)
  23. if err < 0:
  24. exc = convert_error(err)
  25. self._fatal_error(exc, True)
  26. return
  27. @staticmethod
  28. cdef UVAsync new(Loop loop, method_t callback, object ctx):
  29. cdef UVAsync handle
  30. handle = UVAsync.__new__(UVAsync)
  31. handle._init(loop, callback, ctx)
  32. return handle
  33. cdef void __uvasync_callback(uv.uv_async_t* handle) with gil:
  34. if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVAsync callback") == 0:
  35. return
  36. cdef:
  37. UVAsync async_ = <UVAsync> handle.data
  38. method_t cb = async_.callback
  39. try:
  40. cb(async_.ctx)
  41. except BaseException as ex:
  42. async_._error(ex, False)