corecext.pyx 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  1. # Generated by cythonpp.py on 2017-06-05 11:35:20
  2. # Copyright (c) 2009-2012 Denis Bilenko. See LICENSE for details.
  3. # This directive, supported in Cython 0.24+, causes sources files to be
  4. # much smaller and thus cythonpp.py to be slightly faster. But it does make
  5. # debugging more difficult.
  6. # cython: emit_code_comments=False
  7. cimport cython
  8. cimport libev
  9. # Note this is not the standard cython 'cpython' (which has a backwards compat alias of 'python')
  10. # it's our custom def. If it's not on the include path, we get warned.
  11. from python cimport *
  12. # Work around lack of absolute_import in Cython
  13. # Note for PY3: not doing so will leave reference to locals() on import
  14. # (reproducible under Python 3.3, not under Python 3.4; see test__refcount_core.py)
  15. sys = __import__('sys', level=0)
  16. os = __import__('os', level=0)
  17. traceback = __import__('traceback', level=0)
  18. signalmodule = __import__('signal', level=0)
  19. __all__ = ['get_version',
  20. 'get_header_version',
  21. 'supported_backends',
  22. 'recommended_backends',
  23. 'embeddable_backends',
  24. 'time',
  25. 'loop']
  26. cdef tuple integer_types
  27. if sys.version_info[0] >= 3:
  28. integer_types = int,
  29. else:
  30. integer_types = (int, long)
  31. cdef extern from "callbacks.h":
  32. void gevent_callback_io(libev.ev_loop, void*, int)
  33. void gevent_callback_timer(libev.ev_loop, void*, int)
  34. void gevent_callback_signal(libev.ev_loop, void*, int)
  35. void gevent_callback_idle(libev.ev_loop, void*, int)
  36. void gevent_callback_prepare(libev.ev_loop, void*, int)
  37. void gevent_callback_check(libev.ev_loop, void*, int)
  38. void gevent_callback_fork(libev.ev_loop, void*, int)
  39. void gevent_callback_async(libev.ev_loop, void*, int)
  40. void gevent_callback_child(libev.ev_loop, void*, int)
  41. void gevent_callback_stat(libev.ev_loop, void*, int)
  42. void gevent_run_callbacks(libev.ev_loop, void*, int)
  43. void gevent_periodic_signal_check(libev.ev_loop, void*, int)
  44. void gevent_call(loop, callback)
  45. void gevent_noop(libev.ev_loop, void*, int)
  46. cdef extern from *:
  47. int errno
  48. cdef extern from "stathelper.c":
  49. object _pystat_fromstructstat(void*)
  50. UNDEF = libev.EV_UNDEF
  51. NONE = libev.EV_NONE
  52. READ = libev.EV_READ
  53. WRITE = libev.EV_WRITE
  54. TIMER = libev.EV_TIMER
  55. PERIODIC = libev.EV_PERIODIC
  56. SIGNAL = libev.EV_SIGNAL
  57. CHILD = libev.EV_CHILD
  58. STAT = libev.EV_STAT
  59. IDLE = libev.EV_IDLE
  60. PREPARE = libev.EV_PREPARE
  61. CHECK = libev.EV_CHECK
  62. EMBED = libev.EV_EMBED
  63. FORK = libev.EV_FORK
  64. CLEANUP = libev.EV_CLEANUP
  65. ASYNC = libev.EV_ASYNC
  66. CUSTOM = libev.EV_CUSTOM
  67. ERROR = libev.EV_ERROR
  68. READWRITE = libev.EV_READ | libev.EV_WRITE
  69. MINPRI = libev.EV_MINPRI
  70. MAXPRI = libev.EV_MAXPRI
  71. BACKEND_PORT = libev.EVBACKEND_PORT
  72. BACKEND_KQUEUE = libev.EVBACKEND_KQUEUE
  73. BACKEND_EPOLL = libev.EVBACKEND_EPOLL
  74. BACKEND_POLL = libev.EVBACKEND_POLL
  75. BACKEND_SELECT = libev.EVBACKEND_SELECT
  76. FORKCHECK = libev.EVFLAG_FORKCHECK
  77. NOINOTIFY = libev.EVFLAG_NOINOTIFY
  78. SIGNALFD = libev.EVFLAG_SIGNALFD
  79. NOSIGMASK = libev.EVFLAG_NOSIGMASK
  80. @cython.internal
  81. cdef class _EVENTSType:
  82. def __repr__(self):
  83. return 'gevent.core.EVENTS'
  84. cdef public object GEVENT_CORE_EVENTS = _EVENTSType()
  85. EVENTS = GEVENT_CORE_EVENTS
  86. def get_version():
  87. return 'libev-%d.%02d' % (libev.ev_version_major(), libev.ev_version_minor())
  88. def get_header_version():
  89. return 'libev-%d.%02d' % (libev.EV_VERSION_MAJOR, libev.EV_VERSION_MINOR)
  90. # This list backends in the order they are actually tried by libev
  91. _flags = [(libev.EVBACKEND_PORT, 'port'),
  92. (libev.EVBACKEND_KQUEUE, 'kqueue'),
  93. (libev.EVBACKEND_EPOLL, 'epoll'),
  94. (libev.EVBACKEND_POLL, 'poll'),
  95. (libev.EVBACKEND_SELECT, 'select'),
  96. (libev.EVFLAG_NOENV, 'noenv'),
  97. (libev.EVFLAG_FORKCHECK, 'forkcheck'),
  98. (libev.EVFLAG_NOINOTIFY, 'noinotify'),
  99. (libev.EVFLAG_SIGNALFD, 'signalfd'),
  100. (libev.EVFLAG_NOSIGMASK, 'nosigmask')]
  101. _flags_str2int = dict((string, flag) for (flag, string) in _flags)
  102. _events = [(libev.EV_READ, 'READ'),
  103. (libev.EV_WRITE, 'WRITE'),
  104. (libev.EV__IOFDSET, '_IOFDSET'),
  105. (libev.EV_PERIODIC, 'PERIODIC'),
  106. (libev.EV_SIGNAL, 'SIGNAL'),
  107. (libev.EV_CHILD, 'CHILD'),
  108. (libev.EV_STAT, 'STAT'),
  109. (libev.EV_IDLE, 'IDLE'),
  110. (libev.EV_PREPARE, 'PREPARE'),
  111. (libev.EV_CHECK, 'CHECK'),
  112. (libev.EV_EMBED, 'EMBED'),
  113. (libev.EV_FORK, 'FORK'),
  114. (libev.EV_CLEANUP, 'CLEANUP'),
  115. (libev.EV_ASYNC, 'ASYNC'),
  116. (libev.EV_CUSTOM, 'CUSTOM'),
  117. (libev.EV_ERROR, 'ERROR')]
  118. cpdef _flags_to_list(unsigned int flags):
  119. cdef list result = []
  120. for code, value in _flags:
  121. if flags & code:
  122. result.append(value)
  123. flags &= ~code
  124. if not flags:
  125. break
  126. if flags:
  127. result.append(flags)
  128. return result
  129. if sys.version_info[0] >= 3:
  130. basestring = (bytes, str)
  131. else:
  132. basestring = __builtins__.basestring
  133. cpdef unsigned int _flags_to_int(object flags) except? -1:
  134. # Note, that order does not matter, libev has its own predefined order
  135. if not flags:
  136. return 0
  137. if isinstance(flags, integer_types):
  138. return flags
  139. cdef unsigned int result = 0
  140. try:
  141. if isinstance(flags, basestring):
  142. flags = flags.split(',')
  143. for value in flags:
  144. value = value.strip().lower()
  145. if value:
  146. result |= _flags_str2int[value]
  147. except KeyError as ex:
  148. raise ValueError('Invalid backend or flag: %s\nPossible values: %s' % (ex, ', '.join(sorted(_flags_str2int.keys()))))
  149. return result
  150. cdef str _str_hex(object flag):
  151. if isinstance(flag, integer_types):
  152. return hex(flag)
  153. return str(flag)
  154. cpdef _check_flags(unsigned int flags):
  155. cdef list as_list
  156. flags &= libev.EVBACKEND_MASK
  157. if not flags:
  158. return
  159. if not (flags & libev.EVBACKEND_ALL):
  160. raise ValueError('Invalid value for backend: 0x%x' % flags)
  161. if not (flags & libev.ev_supported_backends()):
  162. as_list = [_str_hex(x) for x in _flags_to_list(flags)]
  163. raise ValueError('Unsupported backend: %s' % '|'.join(as_list))
  164. cpdef _events_to_str(int events):
  165. cdef list result = []
  166. cdef int c_flag
  167. for (flag, string) in _events:
  168. c_flag = flag
  169. if events & c_flag:
  170. result.append(string)
  171. events = events & (~c_flag)
  172. if not events:
  173. break
  174. if events:
  175. result.append(hex(events))
  176. return '|'.join(result)
  177. def supported_backends():
  178. return _flags_to_list(libev.ev_supported_backends())
  179. def recommended_backends():
  180. return _flags_to_list(libev.ev_recommended_backends())
  181. def embeddable_backends():
  182. return _flags_to_list(libev.ev_embeddable_backends())
  183. def time():
  184. return libev.ev_time()
  185. cdef bint _default_loop_destroyed = False
  186. cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
  187. cdef libev.ev_loop* _ptr
  188. cdef public object error_handler
  189. cdef libev.ev_prepare _prepare
  190. cdef public list _callbacks
  191. cdef libev.ev_timer _timer0
  192. #ifdef _WIN32
  193. cdef libev.ev_timer _periodic_signal_checker
  194. #endif
  195. def __init__(self, object flags=None, object default=None, size_t ptr=0):
  196. cdef unsigned int c_flags
  197. cdef object old_handler = None
  198. libev.ev_prepare_init(&self._prepare, <void*>gevent_run_callbacks)
  199. #ifdef _WIN32
  200. libev.ev_timer_init(&self._periodic_signal_checker, <void*>gevent_periodic_signal_check, 0.3, 0.3)
  201. #endif
  202. libev.ev_timer_init(&self._timer0, <void*>gevent_noop, 0.0, 0.0)
  203. if ptr:
  204. self._ptr = <libev.ev_loop*>ptr
  205. else:
  206. c_flags = _flags_to_int(flags)
  207. _check_flags(c_flags)
  208. c_flags |= libev.EVFLAG_NOENV
  209. c_flags |= libev.EVFLAG_FORKCHECK
  210. if default is None:
  211. default = True
  212. if _default_loop_destroyed:
  213. default = False
  214. if default:
  215. self._ptr = libev.gevent_ev_default_loop(c_flags)
  216. if not self._ptr:
  217. raise SystemError("ev_default_loop(%s) failed" % (c_flags, ))
  218. #ifdef _WIN32
  219. libev.ev_timer_start(self._ptr, &self._periodic_signal_checker)
  220. libev.ev_unref(self._ptr)
  221. #endif
  222. else:
  223. self._ptr = libev.ev_loop_new(c_flags)
  224. if not self._ptr:
  225. raise SystemError("ev_loop_new(%s) failed" % (c_flags, ))
  226. if default or __SYSERR_CALLBACK is None:
  227. set_syserr_cb(self._handle_syserr)
  228. libev.ev_prepare_start(self._ptr, &self._prepare)
  229. libev.ev_unref(self._ptr)
  230. self._callbacks = []
  231. cdef _run_callbacks(self):
  232. cdef callback cb
  233. cdef object callbacks
  234. cdef int count = 1000
  235. libev.ev_timer_stop(self._ptr, &self._timer0)
  236. while self._callbacks and count > 0:
  237. callbacks = self._callbacks
  238. self._callbacks = []
  239. for cb in callbacks:
  240. libev.ev_unref(self._ptr)
  241. gevent_call(self, cb)
  242. count -= 1
  243. if self._callbacks:
  244. libev.ev_timer_start(self._ptr, &self._timer0)
  245. def _stop_watchers(self):
  246. if libev.ev_is_active(&self._prepare):
  247. libev.ev_ref(self._ptr)
  248. libev.ev_prepare_stop(self._ptr, &self._prepare)
  249. #ifdef _WIN32
  250. if libev.ev_is_active(&self._periodic_signal_checker):
  251. libev.ev_ref(self._ptr)
  252. libev.ev_timer_stop(self._ptr, &self._periodic_signal_checker)
  253. #endif
  254. def destroy(self):
  255. global _default_loop_destroyed
  256. if self._ptr:
  257. self._stop_watchers()
  258. if __SYSERR_CALLBACK == self._handle_syserr:
  259. set_syserr_cb(None)
  260. if libev.ev_is_default_loop(self._ptr):
  261. _default_loop_destroyed = True
  262. libev.ev_loop_destroy(self._ptr)
  263. self._ptr = NULL
  264. def __dealloc__(self):
  265. if self._ptr:
  266. self._stop_watchers()
  267. if not libev.ev_is_default_loop(self._ptr):
  268. libev.ev_loop_destroy(self._ptr)
  269. self._ptr = NULL
  270. property ptr:
  271. def __get__(self):
  272. return <size_t>self._ptr
  273. property WatcherType:
  274. def __get__(self):
  275. return watcher
  276. property MAXPRI:
  277. def __get__(self):
  278. return libev.EV_MAXPRI
  279. property MINPRI:
  280. def __get__(self):
  281. return libev.EV_MINPRI
  282. def _handle_syserr(self, message, errno):
  283. if sys.version_info[0] >= 3:
  284. message = message.decode()
  285. self.handle_error(None, SystemError, SystemError(message + ': ' + os.strerror(errno)), None)
  286. cpdef handle_error(self, context, type, value, tb):
  287. cdef object handle_error
  288. cdef object error_handler = self.error_handler
  289. if error_handler is not None:
  290. # we do want to do getattr every time so that setting Hub.handle_error property just works
  291. handle_error = getattr(error_handler, 'handle_error', error_handler)
  292. handle_error(context, type, value, tb)
  293. else:
  294. self._default_handle_error(context, type, value, tb)
  295. cpdef _default_handle_error(self, context, type, value, tb):
  296. # note: Hub sets its own error handler so this is not used by gevent
  297. # this is here to make core.loop usable without the rest of gevent
  298. traceback.print_exception(type, value, tb)
  299. if self._ptr:
  300. libev.ev_break(self._ptr, libev.EVBREAK_ONE)
  301. def run(self, nowait=False, once=False):
  302. if not self._ptr:
  303. raise ValueError('operation on destroyed loop')
  304. cdef unsigned int flags = 0
  305. if nowait:
  306. flags |= libev.EVRUN_NOWAIT
  307. if once:
  308. flags |= libev.EVRUN_ONCE
  309. with nogil:
  310. libev.ev_run(self._ptr, flags)
  311. def reinit(self):
  312. if self._ptr:
  313. libev.ev_loop_fork(self._ptr)
  314. def ref(self):
  315. if not self._ptr:
  316. raise ValueError('operation on destroyed loop')
  317. libev.ev_ref(self._ptr)
  318. def unref(self):
  319. if not self._ptr:
  320. raise ValueError('operation on destroyed loop')
  321. libev.ev_unref(self._ptr)
  322. def break_(self, int how=libev.EVBREAK_ONE):
  323. if not self._ptr:
  324. raise ValueError('operation on destroyed loop')
  325. libev.ev_break(self._ptr, how)
  326. def verify(self):
  327. if not self._ptr:
  328. raise ValueError('operation on destroyed loop')
  329. libev.ev_verify(self._ptr)
  330. def now(self):
  331. if not self._ptr:
  332. raise ValueError('operation on destroyed loop')
  333. return libev.ev_now(self._ptr)
  334. def update(self):
  335. if not self._ptr:
  336. raise ValueError('operation on destroyed loop')
  337. libev.ev_now_update(self._ptr)
  338. def __repr__(self):
  339. return '<%s at 0x%x %s>' % (self.__class__.__name__, id(self), self._format())
  340. property default:
  341. def __get__(self):
  342. if not self._ptr:
  343. raise ValueError('operation on destroyed loop')
  344. return True if libev.ev_is_default_loop(self._ptr) else False
  345. property iteration:
  346. def __get__(self):
  347. if not self._ptr:
  348. raise ValueError('operation on destroyed loop')
  349. return libev.ev_iteration(self._ptr)
  350. property depth:
  351. def __get__(self):
  352. if not self._ptr:
  353. raise ValueError('operation on destroyed loop')
  354. return libev.ev_depth(self._ptr)
  355. property backend_int:
  356. def __get__(self):
  357. if not self._ptr:
  358. raise ValueError('operation on destroyed loop')
  359. return libev.ev_backend(self._ptr)
  360. property backend:
  361. def __get__(self):
  362. if not self._ptr:
  363. raise ValueError('operation on destroyed loop')
  364. cdef unsigned int backend = libev.ev_backend(self._ptr)
  365. for key, value in _flags:
  366. if key == backend:
  367. return value
  368. return backend
  369. property pendingcnt:
  370. def __get__(self):
  371. if not self._ptr:
  372. raise ValueError('operation on destroyed loop')
  373. return libev.ev_pending_count(self._ptr)
  374. #ifdef _WIN32
  375. def io(self, libev.vfd_socket_t fd, int events, ref=True, priority=None):
  376. return io(self, fd, events, ref, priority)
  377. #else
  378. def io(self, int fd, int events, ref=True, priority=None):
  379. return io(self, fd, events, ref, priority)
  380. #endif
  381. def timer(self, double after, double repeat=0.0, ref=True, priority=None):
  382. return timer(self, after, repeat, ref, priority)
  383. def signal(self, int signum, ref=True, priority=None):
  384. return signal(self, signum, ref, priority)
  385. def idle(self, ref=True, priority=None):
  386. return idle(self, ref, priority)
  387. def prepare(self, ref=True, priority=None):
  388. return prepare(self, ref, priority)
  389. def check(self, ref=True, priority=None):
  390. return check(self, ref, priority)
  391. def fork(self, ref=True, priority=None):
  392. return fork(self, ref, priority)
  393. def async(self, ref=True, priority=None):
  394. return async(self, ref, priority)
  395. #ifdef _WIN32
  396. #else
  397. def child(self, int pid, bint trace=0, ref=True):
  398. return child(self, pid, trace, ref)
  399. def install_sigchld(self):
  400. libev.gevent_install_sigchld_handler()
  401. def reset_sigchld(self):
  402. libev.gevent_reset_sigchld_handler()
  403. #endif
  404. def stat(self, str path, float interval=0.0, ref=True, priority=None):
  405. return stat(self, path, interval, ref, priority)
  406. def run_callback(self, func, *args):
  407. if not self._ptr:
  408. raise ValueError('operation on destroyed loop')
  409. cdef callback cb = callback(func, args)
  410. self._callbacks.append(cb)
  411. libev.ev_ref(self._ptr)
  412. return cb
  413. def _format(self):
  414. if not self._ptr:
  415. return 'destroyed'
  416. cdef object msg = self.backend
  417. if self.default:
  418. msg += ' default'
  419. msg += ' pending=%s' % self.pendingcnt
  420. #ifdef LIBEV_EMBED
  421. msg += self._format_details()
  422. #endif
  423. return msg
  424. #ifdef LIBEV_EMBED
  425. def _format_details(self):
  426. cdef str msg = ''
  427. cdef object fileno = self.fileno()
  428. cdef object sigfd = None
  429. cdef object activecnt = None
  430. try:
  431. sigfd = self.sigfd
  432. except AttributeError:
  433. sigfd = None
  434. try:
  435. activecnt = self.activecnt
  436. except AttributeError:
  437. pass
  438. if activecnt is not None:
  439. msg += ' ref=' + repr(activecnt)
  440. if fileno is not None:
  441. msg += ' fileno=' + repr(fileno)
  442. if sigfd is not None and sigfd != -1:
  443. msg += ' sigfd=' + repr(sigfd)
  444. return msg
  445. def fileno(self):
  446. cdef int fd
  447. if self._ptr:
  448. fd = self._ptr.backend_fd
  449. if fd >= 0:
  450. return fd
  451. property activecnt:
  452. def __get__(self):
  453. if not self._ptr:
  454. raise ValueError('operation on destroyed loop')
  455. return self._ptr.activecnt
  456. property sig_pending:
  457. def __get__(self):
  458. if not self._ptr:
  459. raise ValueError('operation on destroyed loop')
  460. return self._ptr.sig_pending
  461. #if EV_USE_SIGNALFD
  462. property sigfd:
  463. def __get__(self):
  464. if not self._ptr:
  465. raise ValueError('operation on destroyed loop')
  466. return self._ptr.sigfd
  467. #endif
  468. property origflags:
  469. def __get__(self):
  470. if not self._ptr:
  471. raise ValueError('operation on destroyed loop')
  472. return _flags_to_list(self._ptr.origflags)
  473. property origflags_int:
  474. def __get__(self):
  475. if not self._ptr:
  476. raise ValueError('operation on destroyed loop')
  477. return self._ptr.origflags
  478. #endif
  479. cdef public class callback [object PyGeventCallbackObject, type PyGeventCallback_Type]:
  480. cdef public object callback
  481. cdef public tuple args
  482. def __init__(self, callback, args):
  483. self.callback = callback
  484. self.args = args
  485. def stop(self):
  486. self.callback = None
  487. self.args = None
  488. # Note, that __nonzero__ and pending are different
  489. # nonzero is used in contexts where we need to know whether to schedule another callback,
  490. # so it's true if it's pending or currently running
  491. # 'pending' has the same meaning as libev watchers: it is cleared before entering callback
  492. def __nonzero__(self):
  493. # it's nonzero if it's pending or currently executing
  494. return self.args is not None
  495. property pending:
  496. def __get__(self):
  497. return self.callback is not None
  498. def __repr__(self):
  499. if Py_ReprEnter(<PyObjectPtr>self) != 0:
  500. return "<...>"
  501. try:
  502. format = self._format()
  503. result = "<%s at 0x%x%s" % (self.__class__.__name__, id(self), format)
  504. if self.pending:
  505. result += " pending"
  506. if self.callback is not None:
  507. result += " callback=%r" % (self.callback, )
  508. if self.args is not None:
  509. result += " args=%r" % (self.args, )
  510. if self.callback is None and self.args is None:
  511. result += " stopped"
  512. return result + ">"
  513. finally:
  514. Py_ReprLeave(<PyObjectPtr>self)
  515. def _format(self):
  516. return ''
  517. # about readonly _flags attribute:
  518. # bit #1 set if object owns Python reference to itself (Py_INCREF was called and we must call Py_DECREF later)
  519. # bit #2 set if ev_unref() was called and we must call ev_ref() later
  520. # bit #3 set if user wants to call ev_unref() before start()
  521. cdef public class watcher [object PyGeventWatcherObject, type PyGeventWatcher_Type]:
  522. """Abstract base class for all the watchers"""
  523. def __repr__(self):
  524. if Py_ReprEnter(<PyObjectPtr>self) != 0:
  525. return "<...>"
  526. try:
  527. format = self._format()
  528. result = "<%s at 0x%x%s" % (self.__class__.__name__, id(self), format)
  529. if self.active:
  530. result += " active"
  531. if self.pending:
  532. result += " pending"
  533. if self.callback is not None:
  534. result += " callback=%r" % (self.callback, )
  535. if self.args is not None:
  536. result += " args=%r" % (self.args, )
  537. return result + ">"
  538. finally:
  539. Py_ReprLeave(<PyObjectPtr>self)
  540. def _format(self):
  541. return ''
  542. cdef public class io(watcher) [object PyGeventIOObject, type PyGeventIO_Type]:
  543. cdef public loop loop
  544. cdef object _callback
  545. cdef public tuple args
  546. cdef readonly int _flags
  547. cdef libev.ev_io _watcher
  548. property ref:
  549. def __get__(self):
  550. return False if self._flags & 4 else True
  551. def __set__(self, object value):
  552. if not self.loop._ptr:
  553. raise ValueError('operation on destroyed loop')
  554. if value:
  555. if not self._flags & 4:
  556. return # ref is already True
  557. if self._flags & 2: # ev_unref was called, undo
  558. libev.ev_ref(self.loop._ptr)
  559. self._flags &= ~6 # do not want unref, no outstanding unref
  560. else:
  561. if self._flags & 4:
  562. return # ref is already False
  563. self._flags |= 4
  564. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  565. libev.ev_unref(self.loop._ptr)
  566. self._flags |= 2
  567. property callback:
  568. def __get__(self):
  569. return self._callback
  570. def __set__(self, object callback):
  571. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  572. raise TypeError("Expected callable, not %r" % (callback, ))
  573. self._callback = callback
  574. def stop(self):
  575. if not self.loop._ptr:
  576. raise ValueError('operation on destroyed loop')
  577. if self._flags & 2:
  578. libev.ev_ref(self.loop._ptr)
  579. self._flags &= ~2
  580. libev.ev_io_stop(self.loop._ptr, &self._watcher)
  581. self._callback = None
  582. self.args = None
  583. if self._flags & 1:
  584. Py_DECREF(<PyObjectPtr>self)
  585. self._flags &= ~1
  586. property priority:
  587. def __get__(self):
  588. return libev.ev_priority(&self._watcher)
  589. def __set__(self, int priority):
  590. if libev.ev_is_active(&self._watcher):
  591. raise AttributeError("Cannot set priority of an active watcher")
  592. libev.ev_set_priority(&self._watcher, priority)
  593. def feed(self, int revents, object callback, *args):
  594. if not self.loop._ptr:
  595. raise ValueError('operation on destroyed loop')
  596. self.callback = callback
  597. self.args = args
  598. if self._flags & 6 == 4:
  599. libev.ev_unref(self.loop._ptr)
  600. self._flags |= 2
  601. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  602. if not self._flags & 1:
  603. Py_INCREF(<PyObjectPtr>self)
  604. self._flags |= 1
  605. def start(self, object callback, *args, pass_events=False):
  606. if not self.loop._ptr:
  607. raise ValueError('operation on destroyed loop')
  608. if callback is None:
  609. raise TypeError('callback must be callable, not None')
  610. self.callback = callback
  611. if pass_events:
  612. self.args = (GEVENT_CORE_EVENTS, ) + args
  613. else:
  614. self.args = args
  615. if self._flags & 6 == 4:
  616. libev.ev_unref(self.loop._ptr)
  617. self._flags |= 2
  618. libev.ev_io_start(self.loop._ptr, &self._watcher)
  619. if not self._flags & 1:
  620. Py_INCREF(<PyObjectPtr>self)
  621. self._flags |= 1
  622. property active:
  623. def __get__(self):
  624. return True if libev.ev_is_active(&self._watcher) else False
  625. property pending:
  626. def __get__(self):
  627. return True if libev.ev_is_pending(&self._watcher) else False
  628. #ifdef _WIN32
  629. def __init__(self, loop loop, libev.vfd_socket_t fd, int events, ref=True, priority=None):
  630. if events & ~(libev.EV__IOFDSET | libev.EV_READ | libev.EV_WRITE):
  631. raise ValueError('illegal event mask: %r' % events)
  632. cdef int vfd = libev.vfd_open(fd)
  633. libev.vfd_free(self._watcher.fd)
  634. libev.ev_io_init(&self._watcher, <void *>gevent_callback_io, vfd, events)
  635. self.loop = loop
  636. if ref:
  637. self._flags = 0
  638. else:
  639. self._flags = 4
  640. if priority is not None:
  641. libev.ev_set_priority(&self._watcher, priority)
  642. #else
  643. def __init__(self, loop loop, int fd, int events, ref=True, priority=None):
  644. if fd < 0:
  645. raise ValueError('fd must be non-negative: %r' % fd)
  646. if events & ~(libev.EV__IOFDSET | libev.EV_READ | libev.EV_WRITE):
  647. raise ValueError('illegal event mask: %r' % events)
  648. libev.ev_io_init(&self._watcher, <void *>gevent_callback_io, fd, events)
  649. self.loop = loop
  650. if ref:
  651. self._flags = 0
  652. else:
  653. self._flags = 4
  654. if priority is not None:
  655. libev.ev_set_priority(&self._watcher, priority)
  656. #endif
  657. property fd:
  658. def __get__(self):
  659. return libev.vfd_get(self._watcher.fd)
  660. def __set__(self, long fd):
  661. if libev.ev_is_active(&self._watcher):
  662. raise AttributeError("'io' watcher attribute 'fd' is read-only while watcher is active")
  663. cdef int vfd = libev.vfd_open(fd)
  664. libev.vfd_free(self._watcher.fd)
  665. libev.ev_io_init(&self._watcher, <void *>gevent_callback_io, vfd, self._watcher.events)
  666. property events:
  667. def __get__(self):
  668. return self._watcher.events
  669. def __set__(self, int events):
  670. if libev.ev_is_active(&self._watcher):
  671. raise AttributeError("'io' watcher attribute 'events' is read-only while watcher is active")
  672. libev.ev_io_init(&self._watcher, <void *>gevent_callback_io, self._watcher.fd, events)
  673. property events_str:
  674. def __get__(self):
  675. return _events_to_str(self._watcher.events)
  676. def _format(self):
  677. return ' fd=%s events=%s' % (self.fd, self.events_str)
  678. #ifdef _WIN32
  679. def __cinit__(self):
  680. self._watcher.fd = -1;
  681. def __dealloc__(self):
  682. libev.vfd_free(self._watcher.fd)
  683. #endif
  684. cdef public class timer(watcher) [object PyGeventTimerObject, type PyGeventTimer_Type]:
  685. cdef public loop loop
  686. cdef object _callback
  687. cdef public tuple args
  688. cdef readonly int _flags
  689. cdef libev.ev_timer _watcher
  690. property ref:
  691. def __get__(self):
  692. return False if self._flags & 4 else True
  693. def __set__(self, object value):
  694. if not self.loop._ptr:
  695. raise ValueError('operation on destroyed loop')
  696. if value:
  697. if not self._flags & 4:
  698. return # ref is already True
  699. if self._flags & 2: # ev_unref was called, undo
  700. libev.ev_ref(self.loop._ptr)
  701. self._flags &= ~6 # do not want unref, no outstanding unref
  702. else:
  703. if self._flags & 4:
  704. return # ref is already False
  705. self._flags |= 4
  706. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  707. libev.ev_unref(self.loop._ptr)
  708. self._flags |= 2
  709. property callback:
  710. def __get__(self):
  711. return self._callback
  712. def __set__(self, object callback):
  713. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  714. raise TypeError("Expected callable, not %r" % (callback, ))
  715. self._callback = callback
  716. def stop(self):
  717. if not self.loop._ptr:
  718. raise ValueError('operation on destroyed loop')
  719. if self._flags & 2:
  720. libev.ev_ref(self.loop._ptr)
  721. self._flags &= ~2
  722. libev.ev_timer_stop(self.loop._ptr, &self._watcher)
  723. self._callback = None
  724. self.args = None
  725. if self._flags & 1:
  726. Py_DECREF(<PyObjectPtr>self)
  727. self._flags &= ~1
  728. property priority:
  729. def __get__(self):
  730. return libev.ev_priority(&self._watcher)
  731. def __set__(self, int priority):
  732. if libev.ev_is_active(&self._watcher):
  733. raise AttributeError("Cannot set priority of an active watcher")
  734. libev.ev_set_priority(&self._watcher, priority)
  735. def feed(self, int revents, object callback, *args):
  736. if not self.loop._ptr:
  737. raise ValueError('operation on destroyed loop')
  738. self.callback = callback
  739. self.args = args
  740. if self._flags & 6 == 4:
  741. libev.ev_unref(self.loop._ptr)
  742. self._flags |= 2
  743. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  744. if not self._flags & 1:
  745. Py_INCREF(<PyObjectPtr>self)
  746. self._flags |= 1
  747. def start(self, object callback, *args, update=True):
  748. if not self.loop._ptr:
  749. raise ValueError('operation on destroyed loop')
  750. if callback is None:
  751. raise TypeError('callback must be callable, not None')
  752. self.callback = callback
  753. self.args = args
  754. if self._flags & 6 == 4:
  755. libev.ev_unref(self.loop._ptr)
  756. self._flags |= 2
  757. if update:
  758. libev.ev_now_update(self.loop._ptr)
  759. libev.ev_timer_start(self.loop._ptr, &self._watcher)
  760. if not self._flags & 1:
  761. Py_INCREF(<PyObjectPtr>self)
  762. self._flags |= 1
  763. property active:
  764. def __get__(self):
  765. return True if libev.ev_is_active(&self._watcher) else False
  766. property pending:
  767. def __get__(self):
  768. return True if libev.ev_is_pending(&self._watcher) else False
  769. def __init__(self, loop loop, double after=0.0, double repeat=0.0, ref=True, priority=None):
  770. if repeat < 0.0:
  771. raise ValueError("repeat must be positive or zero: %r" % repeat)
  772. libev.ev_timer_init(&self._watcher, <void *>gevent_callback_timer, after, repeat)
  773. self.loop = loop
  774. if ref:
  775. self._flags = 0
  776. else:
  777. self._flags = 4
  778. if priority is not None:
  779. libev.ev_set_priority(&self._watcher, priority)
  780. property at:
  781. def __get__(self):
  782. return self._watcher.at
  783. # QQQ: add 'after' and 'repeat' properties?
  784. def again(self, object callback, *args, update=True):
  785. if not self.loop._ptr:
  786. raise ValueError('operation on destroyed loop')
  787. self.callback = callback
  788. self.args = args
  789. if self._flags & 6 == 4:
  790. libev.ev_unref(self.loop._ptr)
  791. self._flags |= 2
  792. if update:
  793. libev.ev_now_update(self.loop._ptr)
  794. libev.ev_timer_again(self.loop._ptr, &self._watcher)
  795. if not self._flags & 1:
  796. Py_INCREF(<PyObjectPtr>self)
  797. self._flags |= 1
  798. cdef public class signal(watcher) [object PyGeventSignalObject, type PyGeventSignal_Type]:
  799. cdef public loop loop
  800. cdef object _callback
  801. cdef public tuple args
  802. cdef readonly int _flags
  803. cdef libev.ev_signal _watcher
  804. property ref:
  805. def __get__(self):
  806. return False if self._flags & 4 else True
  807. def __set__(self, object value):
  808. if not self.loop._ptr:
  809. raise ValueError('operation on destroyed loop')
  810. if value:
  811. if not self._flags & 4:
  812. return # ref is already True
  813. if self._flags & 2: # ev_unref was called, undo
  814. libev.ev_ref(self.loop._ptr)
  815. self._flags &= ~6 # do not want unref, no outstanding unref
  816. else:
  817. if self._flags & 4:
  818. return # ref is already False
  819. self._flags |= 4
  820. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  821. libev.ev_unref(self.loop._ptr)
  822. self._flags |= 2
  823. property callback:
  824. def __get__(self):
  825. return self._callback
  826. def __set__(self, object callback):
  827. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  828. raise TypeError("Expected callable, not %r" % (callback, ))
  829. self._callback = callback
  830. def stop(self):
  831. if not self.loop._ptr:
  832. raise ValueError('operation on destroyed loop')
  833. if self._flags & 2:
  834. libev.ev_ref(self.loop._ptr)
  835. self._flags &= ~2
  836. libev.ev_signal_stop(self.loop._ptr, &self._watcher)
  837. self._callback = None
  838. self.args = None
  839. if self._flags & 1:
  840. Py_DECREF(<PyObjectPtr>self)
  841. self._flags &= ~1
  842. property priority:
  843. def __get__(self):
  844. return libev.ev_priority(&self._watcher)
  845. def __set__(self, int priority):
  846. if libev.ev_is_active(&self._watcher):
  847. raise AttributeError("Cannot set priority of an active watcher")
  848. libev.ev_set_priority(&self._watcher, priority)
  849. def feed(self, int revents, object callback, *args):
  850. if not self.loop._ptr:
  851. raise ValueError('operation on destroyed loop')
  852. self.callback = callback
  853. self.args = args
  854. if self._flags & 6 == 4:
  855. libev.ev_unref(self.loop._ptr)
  856. self._flags |= 2
  857. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  858. if not self._flags & 1:
  859. Py_INCREF(<PyObjectPtr>self)
  860. self._flags |= 1
  861. def start(self, object callback, *args):
  862. if not self.loop._ptr:
  863. raise ValueError('operation on destroyed loop')
  864. if callback is None:
  865. raise TypeError('callback must be callable, not None')
  866. self.callback = callback
  867. self.args = args
  868. if self._flags & 6 == 4:
  869. libev.ev_unref(self.loop._ptr)
  870. self._flags |= 2
  871. libev.ev_signal_start(self.loop._ptr, &self._watcher)
  872. if not self._flags & 1:
  873. Py_INCREF(<PyObjectPtr>self)
  874. self._flags |= 1
  875. property active:
  876. def __get__(self):
  877. return True if libev.ev_is_active(&self._watcher) else False
  878. property pending:
  879. def __get__(self):
  880. return True if libev.ev_is_pending(&self._watcher) else False
  881. def __init__(self, loop loop, int signalnum, ref=True, priority=None):
  882. if signalnum < 1 or signalnum >= signalmodule.NSIG:
  883. raise ValueError('illegal signal number: %r' % signalnum)
  884. # still possible to crash on one of libev's asserts:
  885. # 1) "libev: ev_signal_start called with illegal signal number"
  886. # EV_NSIG might be different from signal.NSIG on some platforms
  887. # 2) "libev: a signal must not be attached to two different loops"
  888. # we probably could check that in LIBEV_EMBED mode, but not in general
  889. libev.ev_signal_init(&self._watcher, <void *>gevent_callback_signal, signalnum)
  890. self.loop = loop
  891. if ref:
  892. self._flags = 0
  893. else:
  894. self._flags = 4
  895. if priority is not None:
  896. libev.ev_set_priority(&self._watcher, priority)
  897. cdef public class idle(watcher) [object PyGeventIdleObject, type PyGeventIdle_Type]:
  898. cdef public loop loop
  899. cdef object _callback
  900. cdef public tuple args
  901. cdef readonly int _flags
  902. cdef libev.ev_idle _watcher
  903. property ref:
  904. def __get__(self):
  905. return False if self._flags & 4 else True
  906. def __set__(self, object value):
  907. if not self.loop._ptr:
  908. raise ValueError('operation on destroyed loop')
  909. if value:
  910. if not self._flags & 4:
  911. return # ref is already True
  912. if self._flags & 2: # ev_unref was called, undo
  913. libev.ev_ref(self.loop._ptr)
  914. self._flags &= ~6 # do not want unref, no outstanding unref
  915. else:
  916. if self._flags & 4:
  917. return # ref is already False
  918. self._flags |= 4
  919. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  920. libev.ev_unref(self.loop._ptr)
  921. self._flags |= 2
  922. property callback:
  923. def __get__(self):
  924. return self._callback
  925. def __set__(self, object callback):
  926. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  927. raise TypeError("Expected callable, not %r" % (callback, ))
  928. self._callback = callback
  929. def stop(self):
  930. if not self.loop._ptr:
  931. raise ValueError('operation on destroyed loop')
  932. if self._flags & 2:
  933. libev.ev_ref(self.loop._ptr)
  934. self._flags &= ~2
  935. libev.ev_idle_stop(self.loop._ptr, &self._watcher)
  936. self._callback = None
  937. self.args = None
  938. if self._flags & 1:
  939. Py_DECREF(<PyObjectPtr>self)
  940. self._flags &= ~1
  941. property priority:
  942. def __get__(self):
  943. return libev.ev_priority(&self._watcher)
  944. def __set__(self, int priority):
  945. if libev.ev_is_active(&self._watcher):
  946. raise AttributeError("Cannot set priority of an active watcher")
  947. libev.ev_set_priority(&self._watcher, priority)
  948. def feed(self, int revents, object callback, *args):
  949. if not self.loop._ptr:
  950. raise ValueError('operation on destroyed loop')
  951. self.callback = callback
  952. self.args = args
  953. if self._flags & 6 == 4:
  954. libev.ev_unref(self.loop._ptr)
  955. self._flags |= 2
  956. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  957. if not self._flags & 1:
  958. Py_INCREF(<PyObjectPtr>self)
  959. self._flags |= 1
  960. def start(self, object callback, *args):
  961. if not self.loop._ptr:
  962. raise ValueError('operation on destroyed loop')
  963. if callback is None:
  964. raise TypeError('callback must be callable, not None')
  965. self.callback = callback
  966. self.args = args
  967. if self._flags & 6 == 4:
  968. libev.ev_unref(self.loop._ptr)
  969. self._flags |= 2
  970. libev.ev_idle_start(self.loop._ptr, &self._watcher)
  971. if not self._flags & 1:
  972. Py_INCREF(<PyObjectPtr>self)
  973. self._flags |= 1
  974. property active:
  975. def __get__(self):
  976. return True if libev.ev_is_active(&self._watcher) else False
  977. property pending:
  978. def __get__(self):
  979. return True if libev.ev_is_pending(&self._watcher) else False
  980. def __init__(self, loop loop , ref=True, priority=None):
  981. libev.ev_idle_init(&self._watcher, <void *>gevent_callback_idle )
  982. self.loop = loop
  983. if ref:
  984. self._flags = 0
  985. else:
  986. self._flags = 4
  987. if priority is not None:
  988. libev.ev_set_priority(&self._watcher, priority)
  989. cdef public class prepare(watcher) [object PyGeventPrepareObject, type PyGeventPrepare_Type]:
  990. cdef public loop loop
  991. cdef object _callback
  992. cdef public tuple args
  993. cdef readonly int _flags
  994. cdef libev.ev_prepare _watcher
  995. property ref:
  996. def __get__(self):
  997. return False if self._flags & 4 else True
  998. def __set__(self, object value):
  999. if not self.loop._ptr:
  1000. raise ValueError('operation on destroyed loop')
  1001. if value:
  1002. if not self._flags & 4:
  1003. return # ref is already True
  1004. if self._flags & 2: # ev_unref was called, undo
  1005. libev.ev_ref(self.loop._ptr)
  1006. self._flags &= ~6 # do not want unref, no outstanding unref
  1007. else:
  1008. if self._flags & 4:
  1009. return # ref is already False
  1010. self._flags |= 4
  1011. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  1012. libev.ev_unref(self.loop._ptr)
  1013. self._flags |= 2
  1014. property callback:
  1015. def __get__(self):
  1016. return self._callback
  1017. def __set__(self, object callback):
  1018. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  1019. raise TypeError("Expected callable, not %r" % (callback, ))
  1020. self._callback = callback
  1021. def stop(self):
  1022. if not self.loop._ptr:
  1023. raise ValueError('operation on destroyed loop')
  1024. if self._flags & 2:
  1025. libev.ev_ref(self.loop._ptr)
  1026. self._flags &= ~2
  1027. libev.ev_prepare_stop(self.loop._ptr, &self._watcher)
  1028. self._callback = None
  1029. self.args = None
  1030. if self._flags & 1:
  1031. Py_DECREF(<PyObjectPtr>self)
  1032. self._flags &= ~1
  1033. property priority:
  1034. def __get__(self):
  1035. return libev.ev_priority(&self._watcher)
  1036. def __set__(self, int priority):
  1037. if libev.ev_is_active(&self._watcher):
  1038. raise AttributeError("Cannot set priority of an active watcher")
  1039. libev.ev_set_priority(&self._watcher, priority)
  1040. def feed(self, int revents, object callback, *args):
  1041. if not self.loop._ptr:
  1042. raise ValueError('operation on destroyed loop')
  1043. self.callback = callback
  1044. self.args = args
  1045. if self._flags & 6 == 4:
  1046. libev.ev_unref(self.loop._ptr)
  1047. self._flags |= 2
  1048. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  1049. if not self._flags & 1:
  1050. Py_INCREF(<PyObjectPtr>self)
  1051. self._flags |= 1
  1052. def start(self, object callback, *args):
  1053. if not self.loop._ptr:
  1054. raise ValueError('operation on destroyed loop')
  1055. if callback is None:
  1056. raise TypeError('callback must be callable, not None')
  1057. self.callback = callback
  1058. self.args = args
  1059. if self._flags & 6 == 4:
  1060. libev.ev_unref(self.loop._ptr)
  1061. self._flags |= 2
  1062. libev.ev_prepare_start(self.loop._ptr, &self._watcher)
  1063. if not self._flags & 1:
  1064. Py_INCREF(<PyObjectPtr>self)
  1065. self._flags |= 1
  1066. property active:
  1067. def __get__(self):
  1068. return True if libev.ev_is_active(&self._watcher) else False
  1069. property pending:
  1070. def __get__(self):
  1071. return True if libev.ev_is_pending(&self._watcher) else False
  1072. def __init__(self, loop loop , ref=True, priority=None):
  1073. libev.ev_prepare_init(&self._watcher, <void *>gevent_callback_prepare )
  1074. self.loop = loop
  1075. if ref:
  1076. self._flags = 0
  1077. else:
  1078. self._flags = 4
  1079. if priority is not None:
  1080. libev.ev_set_priority(&self._watcher, priority)
  1081. cdef public class check(watcher) [object PyGeventCheckObject, type PyGeventCheck_Type]:
  1082. cdef public loop loop
  1083. cdef object _callback
  1084. cdef public tuple args
  1085. cdef readonly int _flags
  1086. cdef libev.ev_check _watcher
  1087. property ref:
  1088. def __get__(self):
  1089. return False if self._flags & 4 else True
  1090. def __set__(self, object value):
  1091. if not self.loop._ptr:
  1092. raise ValueError('operation on destroyed loop')
  1093. if value:
  1094. if not self._flags & 4:
  1095. return # ref is already True
  1096. if self._flags & 2: # ev_unref was called, undo
  1097. libev.ev_ref(self.loop._ptr)
  1098. self._flags &= ~6 # do not want unref, no outstanding unref
  1099. else:
  1100. if self._flags & 4:
  1101. return # ref is already False
  1102. self._flags |= 4
  1103. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  1104. libev.ev_unref(self.loop._ptr)
  1105. self._flags |= 2
  1106. property callback:
  1107. def __get__(self):
  1108. return self._callback
  1109. def __set__(self, object callback):
  1110. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  1111. raise TypeError("Expected callable, not %r" % (callback, ))
  1112. self._callback = callback
  1113. def stop(self):
  1114. if not self.loop._ptr:
  1115. raise ValueError('operation on destroyed loop')
  1116. if self._flags & 2:
  1117. libev.ev_ref(self.loop._ptr)
  1118. self._flags &= ~2
  1119. libev.ev_check_stop(self.loop._ptr, &self._watcher)
  1120. self._callback = None
  1121. self.args = None
  1122. if self._flags & 1:
  1123. Py_DECREF(<PyObjectPtr>self)
  1124. self._flags &= ~1
  1125. property priority:
  1126. def __get__(self):
  1127. return libev.ev_priority(&self._watcher)
  1128. def __set__(self, int priority):
  1129. if libev.ev_is_active(&self._watcher):
  1130. raise AttributeError("Cannot set priority of an active watcher")
  1131. libev.ev_set_priority(&self._watcher, priority)
  1132. def feed(self, int revents, object callback, *args):
  1133. if not self.loop._ptr:
  1134. raise ValueError('operation on destroyed loop')
  1135. self.callback = callback
  1136. self.args = args
  1137. if self._flags & 6 == 4:
  1138. libev.ev_unref(self.loop._ptr)
  1139. self._flags |= 2
  1140. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  1141. if not self._flags & 1:
  1142. Py_INCREF(<PyObjectPtr>self)
  1143. self._flags |= 1
  1144. def start(self, object callback, *args):
  1145. if not self.loop._ptr:
  1146. raise ValueError('operation on destroyed loop')
  1147. if callback is None:
  1148. raise TypeError('callback must be callable, not None')
  1149. self.callback = callback
  1150. self.args = args
  1151. if self._flags & 6 == 4:
  1152. libev.ev_unref(self.loop._ptr)
  1153. self._flags |= 2
  1154. libev.ev_check_start(self.loop._ptr, &self._watcher)
  1155. if not self._flags & 1:
  1156. Py_INCREF(<PyObjectPtr>self)
  1157. self._flags |= 1
  1158. property active:
  1159. def __get__(self):
  1160. return True if libev.ev_is_active(&self._watcher) else False
  1161. property pending:
  1162. def __get__(self):
  1163. return True if libev.ev_is_pending(&self._watcher) else False
  1164. def __init__(self, loop loop , ref=True, priority=None):
  1165. libev.ev_check_init(&self._watcher, <void *>gevent_callback_check )
  1166. self.loop = loop
  1167. if ref:
  1168. self._flags = 0
  1169. else:
  1170. self._flags = 4
  1171. if priority is not None:
  1172. libev.ev_set_priority(&self._watcher, priority)
  1173. cdef public class fork(watcher) [object PyGeventForkObject, type PyGeventFork_Type]:
  1174. cdef public loop loop
  1175. cdef object _callback
  1176. cdef public tuple args
  1177. cdef readonly int _flags
  1178. cdef libev.ev_fork _watcher
  1179. property ref:
  1180. def __get__(self):
  1181. return False if self._flags & 4 else True
  1182. def __set__(self, object value):
  1183. if not self.loop._ptr:
  1184. raise ValueError('operation on destroyed loop')
  1185. if value:
  1186. if not self._flags & 4:
  1187. return # ref is already True
  1188. if self._flags & 2: # ev_unref was called, undo
  1189. libev.ev_ref(self.loop._ptr)
  1190. self._flags &= ~6 # do not want unref, no outstanding unref
  1191. else:
  1192. if self._flags & 4:
  1193. return # ref is already False
  1194. self._flags |= 4
  1195. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  1196. libev.ev_unref(self.loop._ptr)
  1197. self._flags |= 2
  1198. property callback:
  1199. def __get__(self):
  1200. return self._callback
  1201. def __set__(self, object callback):
  1202. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  1203. raise TypeError("Expected callable, not %r" % (callback, ))
  1204. self._callback = callback
  1205. def stop(self):
  1206. if not self.loop._ptr:
  1207. raise ValueError('operation on destroyed loop')
  1208. if self._flags & 2:
  1209. libev.ev_ref(self.loop._ptr)
  1210. self._flags &= ~2
  1211. libev.ev_fork_stop(self.loop._ptr, &self._watcher)
  1212. self._callback = None
  1213. self.args = None
  1214. if self._flags & 1:
  1215. Py_DECREF(<PyObjectPtr>self)
  1216. self._flags &= ~1
  1217. property priority:
  1218. def __get__(self):
  1219. return libev.ev_priority(&self._watcher)
  1220. def __set__(self, int priority):
  1221. if libev.ev_is_active(&self._watcher):
  1222. raise AttributeError("Cannot set priority of an active watcher")
  1223. libev.ev_set_priority(&self._watcher, priority)
  1224. def feed(self, int revents, object callback, *args):
  1225. if not self.loop._ptr:
  1226. raise ValueError('operation on destroyed loop')
  1227. self.callback = callback
  1228. self.args = args
  1229. if self._flags & 6 == 4:
  1230. libev.ev_unref(self.loop._ptr)
  1231. self._flags |= 2
  1232. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  1233. if not self._flags & 1:
  1234. Py_INCREF(<PyObjectPtr>self)
  1235. self._flags |= 1
  1236. def start(self, object callback, *args):
  1237. if not self.loop._ptr:
  1238. raise ValueError('operation on destroyed loop')
  1239. if callback is None:
  1240. raise TypeError('callback must be callable, not None')
  1241. self.callback = callback
  1242. self.args = args
  1243. if self._flags & 6 == 4:
  1244. libev.ev_unref(self.loop._ptr)
  1245. self._flags |= 2
  1246. libev.ev_fork_start(self.loop._ptr, &self._watcher)
  1247. if not self._flags & 1:
  1248. Py_INCREF(<PyObjectPtr>self)
  1249. self._flags |= 1
  1250. property active:
  1251. def __get__(self):
  1252. return True if libev.ev_is_active(&self._watcher) else False
  1253. property pending:
  1254. def __get__(self):
  1255. return True if libev.ev_is_pending(&self._watcher) else False
  1256. def __init__(self, loop loop , ref=True, priority=None):
  1257. libev.ev_fork_init(&self._watcher, <void *>gevent_callback_fork )
  1258. self.loop = loop
  1259. if ref:
  1260. self._flags = 0
  1261. else:
  1262. self._flags = 4
  1263. if priority is not None:
  1264. libev.ev_set_priority(&self._watcher, priority)
  1265. cdef public class async(watcher) [object PyGeventAsyncObject, type PyGeventAsync_Type]:
  1266. cdef public loop loop
  1267. cdef object _callback
  1268. cdef public tuple args
  1269. cdef readonly int _flags
  1270. cdef libev.ev_async _watcher
  1271. property ref:
  1272. def __get__(self):
  1273. return False if self._flags & 4 else True
  1274. def __set__(self, object value):
  1275. if not self.loop._ptr:
  1276. raise ValueError('operation on destroyed loop')
  1277. if value:
  1278. if not self._flags & 4:
  1279. return # ref is already True
  1280. if self._flags & 2: # ev_unref was called, undo
  1281. libev.ev_ref(self.loop._ptr)
  1282. self._flags &= ~6 # do not want unref, no outstanding unref
  1283. else:
  1284. if self._flags & 4:
  1285. return # ref is already False
  1286. self._flags |= 4
  1287. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  1288. libev.ev_unref(self.loop._ptr)
  1289. self._flags |= 2
  1290. property callback:
  1291. def __get__(self):
  1292. return self._callback
  1293. def __set__(self, object callback):
  1294. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  1295. raise TypeError("Expected callable, not %r" % (callback, ))
  1296. self._callback = callback
  1297. def stop(self):
  1298. if not self.loop._ptr:
  1299. raise ValueError('operation on destroyed loop')
  1300. if self._flags & 2:
  1301. libev.ev_ref(self.loop._ptr)
  1302. self._flags &= ~2
  1303. libev.ev_async_stop(self.loop._ptr, &self._watcher)
  1304. self._callback = None
  1305. self.args = None
  1306. if self._flags & 1:
  1307. Py_DECREF(<PyObjectPtr>self)
  1308. self._flags &= ~1
  1309. property priority:
  1310. def __get__(self):
  1311. return libev.ev_priority(&self._watcher)
  1312. def __set__(self, int priority):
  1313. if libev.ev_is_active(&self._watcher):
  1314. raise AttributeError("Cannot set priority of an active watcher")
  1315. libev.ev_set_priority(&self._watcher, priority)
  1316. def feed(self, int revents, object callback, *args):
  1317. if not self.loop._ptr:
  1318. raise ValueError('operation on destroyed loop')
  1319. self.callback = callback
  1320. self.args = args
  1321. if self._flags & 6 == 4:
  1322. libev.ev_unref(self.loop._ptr)
  1323. self._flags |= 2
  1324. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  1325. if not self._flags & 1:
  1326. Py_INCREF(<PyObjectPtr>self)
  1327. self._flags |= 1
  1328. def start(self, object callback, *args):
  1329. if not self.loop._ptr:
  1330. raise ValueError('operation on destroyed loop')
  1331. if callback is None:
  1332. raise TypeError('callback must be callable, not None')
  1333. self.callback = callback
  1334. self.args = args
  1335. if self._flags & 6 == 4:
  1336. libev.ev_unref(self.loop._ptr)
  1337. self._flags |= 2
  1338. libev.ev_async_start(self.loop._ptr, &self._watcher)
  1339. if not self._flags & 1:
  1340. Py_INCREF(<PyObjectPtr>self)
  1341. self._flags |= 1
  1342. property active:
  1343. def __get__(self):
  1344. return True if libev.ev_is_active(&self._watcher) else False
  1345. property pending:
  1346. def __get__(self):
  1347. return True if libev.ev_async_pending(&self._watcher) else False
  1348. def __init__(self, loop loop , ref=True, priority=None):
  1349. libev.ev_async_init(&self._watcher, <void *>gevent_callback_async )
  1350. self.loop = loop
  1351. if ref:
  1352. self._flags = 0
  1353. else:
  1354. self._flags = 4
  1355. if priority is not None:
  1356. libev.ev_set_priority(&self._watcher, priority)
  1357. def send(self):
  1358. if not self.loop._ptr:
  1359. raise ValueError('operation on destroyed loop')
  1360. libev.ev_async_send(self.loop._ptr, &self._watcher)
  1361. #ifdef _WIN32
  1362. #else
  1363. cdef public class child(watcher) [object PyGeventChildObject, type PyGeventChild_Type]:
  1364. cdef public loop loop
  1365. cdef object _callback
  1366. cdef public tuple args
  1367. cdef readonly int _flags
  1368. cdef libev.ev_child _watcher
  1369. property ref:
  1370. def __get__(self):
  1371. return False if self._flags & 4 else True
  1372. def __set__(self, object value):
  1373. if not self.loop._ptr:
  1374. raise ValueError('operation on destroyed loop')
  1375. if value:
  1376. if not self._flags & 4:
  1377. return # ref is already True
  1378. if self._flags & 2: # ev_unref was called, undo
  1379. libev.ev_ref(self.loop._ptr)
  1380. self._flags &= ~6 # do not want unref, no outstanding unref
  1381. else:
  1382. if self._flags & 4:
  1383. return # ref is already False
  1384. self._flags |= 4
  1385. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  1386. libev.ev_unref(self.loop._ptr)
  1387. self._flags |= 2
  1388. property callback:
  1389. def __get__(self):
  1390. return self._callback
  1391. def __set__(self, object callback):
  1392. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  1393. raise TypeError("Expected callable, not %r" % (callback, ))
  1394. self._callback = callback
  1395. def stop(self):
  1396. if not self.loop._ptr:
  1397. raise ValueError('operation on destroyed loop')
  1398. if self._flags & 2:
  1399. libev.ev_ref(self.loop._ptr)
  1400. self._flags &= ~2
  1401. libev.ev_child_stop(self.loop._ptr, &self._watcher)
  1402. self._callback = None
  1403. self.args = None
  1404. if self._flags & 1:
  1405. Py_DECREF(<PyObjectPtr>self)
  1406. self._flags &= ~1
  1407. property priority:
  1408. def __get__(self):
  1409. return libev.ev_priority(&self._watcher)
  1410. def __set__(self, int priority):
  1411. if libev.ev_is_active(&self._watcher):
  1412. raise AttributeError("Cannot set priority of an active watcher")
  1413. libev.ev_set_priority(&self._watcher, priority)
  1414. def feed(self, int revents, object callback, *args):
  1415. if not self.loop._ptr:
  1416. raise ValueError('operation on destroyed loop')
  1417. self.callback = callback
  1418. self.args = args
  1419. if self._flags & 6 == 4:
  1420. libev.ev_unref(self.loop._ptr)
  1421. self._flags |= 2
  1422. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  1423. if not self._flags & 1:
  1424. Py_INCREF(<PyObjectPtr>self)
  1425. self._flags |= 1
  1426. def start(self, object callback, *args):
  1427. if not self.loop._ptr:
  1428. raise ValueError('operation on destroyed loop')
  1429. if callback is None:
  1430. raise TypeError('callback must be callable, not None')
  1431. self.callback = callback
  1432. self.args = args
  1433. if self._flags & 6 == 4:
  1434. libev.ev_unref(self.loop._ptr)
  1435. self._flags |= 2
  1436. libev.ev_child_start(self.loop._ptr, &self._watcher)
  1437. if not self._flags & 1:
  1438. Py_INCREF(<PyObjectPtr>self)
  1439. self._flags |= 1
  1440. property active:
  1441. def __get__(self):
  1442. return True if libev.ev_is_active(&self._watcher) else False
  1443. property pending:
  1444. def __get__(self):
  1445. return True if libev.ev_is_pending(&self._watcher) else False
  1446. def __init__(self, loop loop, int pid, bint trace=0, ref=True):
  1447. if not loop.default:
  1448. raise TypeError('child watchers are only available on the default loop')
  1449. libev.gevent_install_sigchld_handler()
  1450. libev.ev_child_init(&self._watcher, <void *>gevent_callback_child, pid, trace)
  1451. self.loop = loop
  1452. if ref:
  1453. self._flags = 0
  1454. else:
  1455. self._flags = 4
  1456. def _format(self):
  1457. return ' pid=%r rstatus=%r' % (self.pid, self.rstatus)
  1458. property pid:
  1459. def __get__(self):
  1460. return self._watcher.pid
  1461. property rpid:
  1462. def __get__(self):
  1463. return self._watcher.rpid
  1464. def __set__(self, int value):
  1465. self._watcher.rpid = value
  1466. property rstatus:
  1467. def __get__(self):
  1468. return self._watcher.rstatus
  1469. def __set__(self, int value):
  1470. self._watcher.rstatus = value
  1471. #endif
  1472. cdef public class stat(watcher) [object PyGeventStatObject, type PyGeventStat_Type]:
  1473. cdef public loop loop
  1474. cdef object _callback
  1475. cdef public tuple args
  1476. cdef readonly int _flags
  1477. cdef libev.ev_stat _watcher
  1478. property ref:
  1479. def __get__(self):
  1480. return False if self._flags & 4 else True
  1481. def __set__(self, object value):
  1482. if not self.loop._ptr:
  1483. raise ValueError('operation on destroyed loop')
  1484. if value:
  1485. if not self._flags & 4:
  1486. return # ref is already True
  1487. if self._flags & 2: # ev_unref was called, undo
  1488. libev.ev_ref(self.loop._ptr)
  1489. self._flags &= ~6 # do not want unref, no outstanding unref
  1490. else:
  1491. if self._flags & 4:
  1492. return # ref is already False
  1493. self._flags |= 4
  1494. if not self._flags & 2 and libev.ev_is_active(&self._watcher):
  1495. libev.ev_unref(self.loop._ptr)
  1496. self._flags |= 2
  1497. property callback:
  1498. def __get__(self):
  1499. return self._callback
  1500. def __set__(self, object callback):
  1501. if not PyCallable_Check(<PyObjectPtr>callback) and callback is not None:
  1502. raise TypeError("Expected callable, not %r" % (callback, ))
  1503. self._callback = callback
  1504. def stop(self):
  1505. if not self.loop._ptr:
  1506. raise ValueError('operation on destroyed loop')
  1507. if self._flags & 2:
  1508. libev.ev_ref(self.loop._ptr)
  1509. self._flags &= ~2
  1510. libev.ev_stat_stop(self.loop._ptr, &self._watcher)
  1511. self._callback = None
  1512. self.args = None
  1513. if self._flags & 1:
  1514. Py_DECREF(<PyObjectPtr>self)
  1515. self._flags &= ~1
  1516. property priority:
  1517. def __get__(self):
  1518. return libev.ev_priority(&self._watcher)
  1519. def __set__(self, int priority):
  1520. if libev.ev_is_active(&self._watcher):
  1521. raise AttributeError("Cannot set priority of an active watcher")
  1522. libev.ev_set_priority(&self._watcher, priority)
  1523. def feed(self, int revents, object callback, *args):
  1524. if not self.loop._ptr:
  1525. raise ValueError('operation on destroyed loop')
  1526. self.callback = callback
  1527. self.args = args
  1528. if self._flags & 6 == 4:
  1529. libev.ev_unref(self.loop._ptr)
  1530. self._flags |= 2
  1531. libev.ev_feed_event(self.loop._ptr, &self._watcher, revents)
  1532. if not self._flags & 1:
  1533. Py_INCREF(<PyObjectPtr>self)
  1534. self._flags |= 1
  1535. def start(self, object callback, *args):
  1536. if not self.loop._ptr:
  1537. raise ValueError('operation on destroyed loop')
  1538. if callback is None:
  1539. raise TypeError('callback must be callable, not None')
  1540. self.callback = callback
  1541. self.args = args
  1542. if self._flags & 6 == 4:
  1543. libev.ev_unref(self.loop._ptr)
  1544. self._flags |= 2
  1545. libev.ev_stat_start(self.loop._ptr, &self._watcher)
  1546. if not self._flags & 1:
  1547. Py_INCREF(<PyObjectPtr>self)
  1548. self._flags |= 1
  1549. property active:
  1550. def __get__(self):
  1551. return True if libev.ev_is_active(&self._watcher) else False
  1552. property pending:
  1553. def __get__(self):
  1554. return True if libev.ev_is_pending(&self._watcher) else False
  1555. cdef readonly str path
  1556. cdef readonly bytes _paths
  1557. def __init__(self, loop loop, str path, float interval=0.0, ref=True, priority=None):
  1558. self.path = path
  1559. cdef bytes paths
  1560. if isinstance(path, unicode):
  1561. # the famous Python3 filesystem encoding debacle hits us here. Can we do better?
  1562. # We must keep a reference to the encoded string so that its bytes don't get freed
  1563. # and overwritten, leading to strange errors from libev ("no such file or directory")
  1564. paths = (<unicode>path).encode(sys.getfilesystemencoding())
  1565. self._paths = paths
  1566. else:
  1567. paths = <bytes>path
  1568. self._paths = paths
  1569. libev.ev_stat_init(&self._watcher, <void *>gevent_callback_stat, <char*>paths, interval)
  1570. self.loop = loop
  1571. if ref:
  1572. self._flags = 0
  1573. else:
  1574. self._flags = 4
  1575. if priority is not None:
  1576. libev.ev_set_priority(&self._watcher, priority)
  1577. property attr:
  1578. def __get__(self):
  1579. if not self._watcher.attr.st_nlink:
  1580. return
  1581. return _pystat_fromstructstat(&self._watcher.attr)
  1582. property prev:
  1583. def __get__(self):
  1584. if not self._watcher.prev.st_nlink:
  1585. return
  1586. return _pystat_fromstructstat(&self._watcher.prev)
  1587. property interval:
  1588. def __get__(self):
  1589. return self._watcher.interval
  1590. __SYSERR_CALLBACK = None
  1591. cdef void _syserr_cb(char* msg) with gil:
  1592. try:
  1593. __SYSERR_CALLBACK(msg, errno)
  1594. except:
  1595. set_syserr_cb(None)
  1596. print_exc = getattr(traceback, 'print_exc', None)
  1597. if print_exc is not None:
  1598. print_exc()
  1599. cpdef set_syserr_cb(callback):
  1600. global __SYSERR_CALLBACK
  1601. if callback is None:
  1602. libev.ev_set_syserr_cb(NULL)
  1603. __SYSERR_CALLBACK = None
  1604. elif callable(callback):
  1605. libev.ev_set_syserr_cb(<void *>_syserr_cb)
  1606. __SYSERR_CALLBACK = callback
  1607. else:
  1608. raise TypeError('Expected callable or None, got %r' % (callback, ))
  1609. #ifdef LIBEV_EMBED
  1610. LIBEV_EMBED = True
  1611. EV_USE_FLOOR = libev.EV_USE_FLOOR
  1612. EV_USE_CLOCK_SYSCALL = libev.EV_USE_CLOCK_SYSCALL
  1613. EV_USE_REALTIME = libev.EV_USE_REALTIME
  1614. EV_USE_MONOTONIC = libev.EV_USE_MONOTONIC
  1615. EV_USE_NANOSLEEP = libev.EV_USE_NANOSLEEP
  1616. EV_USE_INOTIFY = libev.EV_USE_INOTIFY
  1617. EV_USE_SIGNALFD = libev.EV_USE_SIGNALFD
  1618. EV_USE_EVENTFD = libev.EV_USE_EVENTFD
  1619. EV_USE_4HEAP = libev.EV_USE_4HEAP
  1620. #else
  1621. LIBEV_EMBED = False
  1622. #endif