Commit 00b173cc authored by Jason Madden's avatar Jason Madden

backport fix for #805.

parent 08080428
......@@ -13,6 +13,8 @@
- :class:`selectors.SelectSelector` is properly monkey-patched
regardless of the order of imports. Reported in :issue:`835` by
Przemysław Węgrzyn.
- Python 2: ``reload(site)`` no longer fails with a ``TypeError`` if
gevent has been imported. Reported in :issue:`805` by Jake Hilton.
1.1.1 (Apr 4, 2016)
===================
......
......@@ -82,9 +82,10 @@ class _signal_metaclass(type):
return getattr(_signal_module, name)
def __setattr__(self, name, value):
# Because we can't know whether to try to go to the module
# or the class, we don't allow setting an attribute after the fact
raise TypeError("Cannot set attribute")
# For symmetry with getattr and dir, pass all
# attribute setting on to the module. (This makes
# reloading work, see issue #805)
setattr(_signal_module, name, value)
def __instancecheck__(self, instance):
return isinstance(instance, _signal_class)
......
......@@ -476,10 +476,10 @@ def patch_select(aggressive=True):
assert select.select is not orig_select_select
selectors = __import__('selectors')
if selectors.SelectSelector._select in (select.select, orig_select_select):
def _select(self, *args, **kwargs): # pylint:disable=unused-argument
return select.select(*args, **kwargs)
selectors.SelectSelector._select = _select
_select._gevent_monkey = True
def _select(self, *args, **kwargs): # pylint:disable=unused-argument
return select.select(*args, **kwargs)
selectors.SelectSelector._select = _select
_select._gevent_monkey = True
if aggressive:
# If `selectors` had already been imported before we removed
......
......@@ -71,12 +71,19 @@ PLATFORM_SPECIFIC_SUFFIXES = ['2', '279', '3']
if sys.platform.startswith('win'):
PLATFORM_SPECIFIC_SUFFIXES.append('posix')
PY2 = None
PY3 = None
PY34 = None
NON_APPLICABLE_SUFFIXES = []
if sys.version_info[0] == 3:
# Python 3
NON_APPLICABLE_SUFFIXES.extend(('2', '279'))
PY2 = False
PY3 = True
if sys.version_info[1] >= 4:
PY34 = True
if sys.version_info[0] == 2:
# Any python 2
PY3 = False
......@@ -157,6 +164,11 @@ def wrap_timeout(timeout, method):
return wrapped
def ignores_leakcheck(func):
func.ignore_leakcheck = True
return func
def wrap_refcount(method):
if not RUN_LEAKCHECKS:
return method
......
......@@ -41,6 +41,30 @@ if hasattr(signal, 'SIGALRM'):
finally:
sig.cancel()
@greentest.ignores_leakcheck
def test_reload(self):
# The site module tries to set attributes
# on all the modules that are loaded (specifically, __file__).
# If gevent.signal is loaded, and is our compatibility shim,
# this used to fail on Python 2: sys.modules['gevent.signal'] has no
# __loader__ attribute, so site.py's main() function tries to do
# gevent.signal.__file__ = os.path.abspath(gevent.signal.__file__), which
# used to not be allowed. (Under Python 3, __loader__ is present so this
# doesn't happen). See
# https://github.com/gevent/gevent/issues/805
import gevent.signal # make sure it's in sys.modules pylint:disable=redefined-outer-name
assert gevent.signal
import site
if greentest.PY34:
from importlib import reload as reload_module
elif greentest.PY3:
from imp import reload as reload_module
else:
# builtin on py2
reload_module = reload # pylint:disable=undefined-variable
reload_module(site)
if __name__ == '__main__':
greentest.main()
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