Skip to content

Commit

Permalink
Add uvloop.loop.Handle.get_callback()
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Feb 4, 2023
1 parent 57d7fba commit 0fd3634
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,19 @@ def test_get_ready_queue(self):
l2 = len(self.loop.get_ready_queue())
self.assertEqual(l1, l2-1)

def test_ready_handle(self):
def cb(a, b):
return None
args = 1, 2
self.loop.call_soon(cb, *args)
handle = list(self.loop.get_ready_queue())[-1]
self.assertIsInstance(handle, uvloop.loop.Handle)
cb2, args2 = handle.get_callback()
self.assertIs(cb, cb2)
self.assertEqual(args, args2)
#import uvloop.handles
#self.assertIsInstance(last, uvloop.handles.Handle)


class TestBaseAIO(_TestBase, AIOTestCase):
pass
Expand Down
10 changes: 10 additions & 0 deletions uvloop/cbhandles.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ cdef class Handle:
def cancelled(self):
return self._cancelled

def get_callback(self):
"""
Allow access to a python callback and its args.
Return a (callback, args) tuple or None if it is an
internal callback.
"""
if self.cb_type == 1:
return self.arg1, self.arg2
return None


@cython.no_gc_clear
@cython.freelist(DEFAULT_FREELIST_SIZE)
Expand Down

0 comments on commit 0fd3634

Please sign in to comment.