Commit 5e6c1bcf authored by Jason Madden's avatar Jason Madden

Stop accessing private _links variable.

parent a268865b
...@@ -36,15 +36,14 @@ cdef class Greenlet(greenlet): ...@@ -36,15 +36,14 @@ cdef class Greenlet(greenlet):
cdef public dict spawn_tree_locals cdef public dict spawn_tree_locals
cdef readonly _Frame spawning_stack cdef readonly _Frame spawning_stack
# A test case reads this, otherwise they would
# be private
cdef readonly list _links
cdef object tuple _exc_info cdef list _links
cdef tuple _exc_info
cdef object _notifier cdef object _notifier
cdef object _start_event cdef object _start_event
cdef dict _kwargs cdef dict _kwargs
cpdef bint has_links(self)
cdef bint __started_but_aborted(self) cdef bint __started_but_aborted(self)
cdef bint __start_cancelled_by_kill(self) cdef bint __start_cancelled_by_kill(self)
......
...@@ -674,6 +674,9 @@ class Greenlet(greenlet): ...@@ -674,6 +674,9 @@ class Greenlet(greenlet):
# pylint: disable=method-hidden # pylint: disable=method-hidden
return return
def has_links(self):
return len(self._links)
def rawlink(self, callback): def rawlink(self, callback):
"""Register a callable to be executed when the greenlet finishes execution. """Register a callable to be executed when the greenlet finishes execution.
...@@ -708,6 +711,14 @@ class Greenlet(greenlet): ...@@ -708,6 +711,14 @@ class Greenlet(greenlet):
except ValueError: except ValueError:
pass pass
def unlink_all(self):
"""
Remove all the callbacks.
.. versionadded:: 1.3a2
"""
del self._links[:]
def link_value(self, callback, SpawnedLink=SuccessSpawnedLink): def link_value(self, callback, SpawnedLink=SuccessSpawnedLink):
""" """
Like :meth:`link` but *callback* is only notified when the greenlet Like :meth:`link` but *callback* is only notified when the greenlet
......
...@@ -96,14 +96,17 @@ class TestUnlink(greentest.TestCase): ...@@ -96,14 +96,17 @@ class TestUnlink(greentest.TestCase):
def _test_func(self, p, link): def _test_func(self, p, link):
link(dummy_test_func) link(dummy_test_func)
assert len(p._links) == 1, p._links self.assertEqual(1, p.has_links())
p.unlink(dummy_test_func) p.unlink(dummy_test_func)
assert not p._links, p._links self.assertEqual(0, p.has_links())
link(self.setUp) link(self.setUp)
assert len(p._links) == 1, p._links self.assertEqual(1, p.has_links())
p.unlink(self.setUp) p.unlink(self.setUp)
assert not p._links, p._links self.assertEqual(0, p.has_links())
p.kill() p.kill()
def test_func_link(self): def test_func_link(self):
...@@ -170,8 +173,7 @@ class TestReturn_link(LinksTestCase): ...@@ -170,8 +173,7 @@ class TestReturn_link(LinksTestCase):
p = None p = None
def cleanup(self): def cleanup(self):
while self.p._links: self.p.unlink_all()
self.p._links.pop()
self.p = None self.p = None
def test_return(self): def test_return(self):
......
...@@ -273,7 +273,7 @@ class GeventLocalTestCase(greentest.TestCase): ...@@ -273,7 +273,7 @@ class GeventLocalTestCase(greentest.TestCase):
self.assertEqual(count, len(deleted_sentinels)) self.assertEqual(count, len(deleted_sentinels))
# The links were removed as well. # The links were removed as well.
self.assertEqual(list(running_greenlet._links), []) self.assertFalse(running_greenlet.has_links())
running_greenlet = gevent.spawn(demonstrate_my_local) running_greenlet = gevent.spawn(demonstrate_my_local)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment