Commit db623899 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1214 from gevent/issue1211

 Let Event have weak references.
parents e6d9991e 368d6a91
......@@ -7,7 +7,8 @@
1.3.1 (unreleased)
==================
- Nothing changed yet.
- Fix weak references to :class:`gevent.event.Event`. Reported in
:issue:`1211` by Matias Guijarro.
- Fix embedded uses of :func:`gevent.Greenlet.spawn`, especially under
uwsgi. Reported in :issue:`1212` by Kunal Gangakhedkar.
......
......@@ -36,6 +36,11 @@ cdef inline void greenlet_init():
cdef void _init()
cdef class _AbstractLinkable:
# We declare the __weakref__ here in the base (even though
# that's not really what we want) as a workaround for a Cython
# issue we see reliably on 3.7b4 and sometimes on 3.6. See
# https://github.com/cython/cython/issues/2270
cdef object __weakref__
cdef _notifier
cdef set _links
cdef readonly SwitchOutGreenletWithLoop hub
......@@ -55,7 +60,6 @@ cdef class _AbstractLinkable:
cdef class Event(_AbstractLinkable):
cdef bint _flag
cdef class AsyncResult(_AbstractLinkable):
cdef readonly _value
cdef readonly tuple _exc_info
......
......@@ -157,7 +157,7 @@ class Event(_AbstractLinkable):
the waiting greenlets being awakened. These details may change in the future.
"""
__slots__ = ('_flag',)
__slots__ = ('_flag', '__weakref__')
def __init__(self):
_AbstractLinkable.__init__(self)
......
......@@ -78,6 +78,7 @@ from greentest.skipping import skipOnLibuvOnPyPyOnWin
from greentest.skipping import skipOnPurePython
from greentest.skipping import skipWithCExtensions
from greentest.skipping import skipOnLibuvOnTravisOnCPython27
from greentest.skipping import skipOnPy37
from greentest.exception import ExpectedException
......
......@@ -41,6 +41,8 @@ skipOnPyPy3OnCI = _do_not_skip
skipOnPyPy3 = _do_not_skip
skipOnPyPyOnWindows = _do_not_skip
skipOnPy37 = unittest.skip if sysinfo.PY37 else _do_not_skip
skipOnPurePython = unittest.skip if sysinfo.PURE_PYTHON else _do_not_skip
skipWithCExtensions = unittest.skip if not sysinfo.PURE_PYTHON else _do_not_skip
......
from __future__ import absolute_import, print_function, division
import weakref
import gevent
from gevent.event import Event, AsyncResult
......@@ -234,6 +236,16 @@ class TestWait_count1(TestWait):
class TestWait_count2(TestWait):
count = 2
class TestEventBasics(greentest.TestCase):
def test_weakref(self):
# Event objects should allow weakrefs
e = Event()
r = weakref.ref(e)
self.assertIs(e, r())
del e
del r
del AbstractGenericGetTestCase
del AbstractGenericWaitTestCase
......
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