您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

71 行
1.8 KiB

  1. @cython.no_gc_clear
  2. cdef class UVCheck(UVHandle):
  3. cdef _init(self, Loop loop, Handle h):
  4. cdef int err
  5. self._start_init(loop)
  6. self._handle = <uv.uv_handle_t*>PyMem_RawMalloc(sizeof(uv.uv_check_t))
  7. if self._handle is NULL:
  8. self._abort_init()
  9. raise MemoryError()
  10. err = uv.uv_check_init(self._loop.uvloop, <uv.uv_check_t*>self._handle)
  11. if err < 0:
  12. self._abort_init()
  13. raise convert_error(err)
  14. self._finish_init()
  15. self.h = h
  16. self.running = 0
  17. cdef inline stop(self):
  18. cdef int err
  19. if not self._is_alive():
  20. self.running = 0
  21. return
  22. if self.running == 1:
  23. err = uv.uv_check_stop(<uv.uv_check_t*>self._handle)
  24. self.running = 0
  25. if err < 0:
  26. exc = convert_error(err)
  27. self._fatal_error(exc, True)
  28. return
  29. cdef inline start(self):
  30. cdef int err
  31. self._ensure_alive()
  32. if self.running == 0:
  33. err = uv.uv_check_start(<uv.uv_check_t*>self._handle,
  34. cb_check_callback)
  35. if err < 0:
  36. exc = convert_error(err)
  37. self._fatal_error(exc, True)
  38. return
  39. self.running = 1
  40. @staticmethod
  41. cdef UVCheck new(Loop loop, Handle h):
  42. cdef UVCheck handle
  43. handle = UVCheck.__new__(UVCheck)
  44. handle._init(loop, h)
  45. return handle
  46. cdef void cb_check_callback(uv.uv_check_t* handle) with gil:
  47. if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVCheck callback") == 0:
  48. return
  49. cdef:
  50. UVCheck check = <UVCheck> handle.data
  51. Handle h = check.h
  52. try:
  53. h._run()
  54. except BaseException as ex:
  55. check._error(ex, False)