Skip to content

Commit 0fd3634

Browse files
committed
Add uvloop.loop.Handle.get_callback()
1 parent 57d7fba commit 0fd3634

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/test_base.py

+13
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,19 @@ def test_get_ready_queue(self):
879879
l2 = len(self.loop.get_ready_queue())
880880
self.assertEqual(l1, l2-1)
881881

882+
def test_ready_handle(self):
883+
def cb(a, b):
884+
return None
885+
args = 1, 2
886+
self.loop.call_soon(cb, *args)
887+
handle = list(self.loop.get_ready_queue())[-1]
888+
self.assertIsInstance(handle, uvloop.loop.Handle)
889+
cb2, args2 = handle.get_callback()
890+
self.assertIs(cb, cb2)
891+
self.assertEqual(args, args2)
892+
#import uvloop.handles
893+
#self.assertIsInstance(last, uvloop.handles.Handle)
894+
882895

883896
class TestBaseAIO(_TestBase, AIOTestCase):
884897
pass

uvloop/cbhandles.pyx

+10
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ cdef class Handle:
161161
def cancelled(self):
162162
return self._cancelled
163163

164+
def get_callback(self):
165+
"""
166+
Allow access to a python callback and its args.
167+
Return a (callback, args) tuple or None if it is an
168+
internal callback.
169+
"""
170+
if self.cb_type == 1:
171+
return self.arg1, self.arg2
172+
return None
173+
164174

165175
@cython.no_gc_clear
166176
@cython.freelist(DEFAULT_FREELIST_SIZE)

0 commit comments

Comments
 (0)