Commit a6ee9283 authored by Jason Madden's avatar Jason Madden

Let Event have weak references.

Fixes #1211

Note that this can crash on CPython 3.7b4; see https://github.com/cython/cython/issues/2270
parent 5e1aab55
......@@ -7,7 +7,9 @@
1.3.1 (unreleased)
==================
- Nothing changed yet.
- Fix weak references to :class:`gevent.event.Event`. Reported in
:issue:`1211` by Matias Guijarro. Note that creating weak references
to Event objects may crash Python 3.7.
1.3.0 (2018-05-11)
......
......@@ -53,9 +53,9 @@ cdef class _AbstractLinkable:
cdef class Event(_AbstractLinkable):
cdef object __weakref__
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):
@greentest.skipOnPy37("Cython crashes in this case. "
"See https://github.com/cython/cython/issues/2270")
def test_weakref(self):
# Event objects should allow weakrefs
e = Event()
r = weakref.ref(e)
self.assertIs(e, 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