Commit d646202b authored by Jason Madden's avatar Jason Madden

Make sure gevent.lock.Semaphore can be weak referenced. This must be...

Make sure gevent.lock.Semaphore can be weak referenced. This must be explicitly declared in cython. Fixes #666.
parent 61732489
......@@ -27,6 +27,10 @@
especially important for PyPy.
- Request logging by :mod:`gevent.pywsgi` formats the status code
correctly on Python 3. Reported in :issue:`664` by Kevin Chen.
- Restore the ability to take a weak reference to instances of exactly
:class:`gevent.lock.Semaphore`, which was unintentionally removed
as part of making ``Semaphore`` atomic on PyPy on 1.1b1. Reported in
:issue:`666` by Ivan-Zhu.
.. _details: https://mail.python.org/pipermail/cython-devel/2015-October/004571.html
......@@ -162,7 +166,7 @@
- ``setup.py`` can build with newer versions of clang on OS X. They
enforce the distinction between CFLAGS and CPPFLAGS.
- ``gevent.lock.Semaphore`` is atomic on PyPy, just like it is on
CPython. This comes at a small performance cost.
CPython. This comes at a small performance cost on PyPy.
- Fixed regression that failed to set the ``successful`` value to
False when killing a greenlet before it ran with a non-default
exception. Fixed in :pr:`608` by Heungsub Lee.
......
......@@ -3,6 +3,7 @@ cdef class Semaphore:
cdef readonly object _links
cdef readonly object _notifier
cdef public int _dirty
cdef object __weakref__
cpdef bint locked(self)
cpdef int release(self) except -1000
......
......@@ -2,13 +2,14 @@ import greentest
import gevent
from gevent.lock import Semaphore
from gevent.thread import allocate_lock
import weakref
try:
from _thread import allocate_lock as std_allocate_lock
except ImportError: # Py2
from thread import allocate_lock as std_allocate_lock
class TestTimeoutAcquire(greentest.TestCase):
class TestSemaphore(greentest.TestCase):
# issue 39
def test_acquire_returns_false_after_timeout(self):
......@@ -26,6 +27,12 @@ class TestTimeoutAcquire(greentest.TestCase):
gevent.sleep(0.001)
self.assertEqual(result, ['a', 'b'])
def test_semaphore_weakref(self):
s = Semaphore()
r = weakref.ref(s)
self.assertEqual(s, r())
class TestLock(greentest.TestCase):
......
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