Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.set_coroutine_wrapper will be removed in Python 3.8 #251

Closed
encukou opened this issue Jun 7, 2019 · 4 comments · Fixed by #253
Closed

sys.set_coroutine_wrapper will be removed in Python 3.8 #251

encukou opened this issue Jun 7, 2019 · 4 comments · Fixed by #253

Comments

@encukou
Copy link

encukou commented Jun 7, 2019

  • uvloop version: master (cbbac15)
  • Python version: 3.8.0b1
  • Cython version: 0.29.10 (updated for Python 3.8 support)
  • Platform: Fedora
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes

The function "sys.set_coroutine_wrapper", which was provisionally added to Python 3.5 and deprecated in Python 3.7, will be removed in Python 3.8. If uvloop needs it, now is the last chance to make the case for it.

When compiled with Python 3.8.0b1, uvloop fails to import:

Python 3.8.0b1 (default, Jun  5 2019, 14:47:51) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import uvloop
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pviktori/dev/uvloop/uvloop/__init__.py", line 7, in <module>
    from .loop import Loop as __BaseLoop  # NOQA
  File "uvloop/includes/stdlib.pxi", line 119, in init uvloop.loop
    cdef sys_set_coroutine_wrapper = sys.set_coroutine_wrapper
AttributeError: module 'sys' has no attribute 'set_coroutine_wrapper'
@1st1
Copy link
Member

1st1 commented Jun 7, 2019

No, we don't need it. We'll have to fix the compatibility with 3.8 at some point though.

@hroncok
Copy link
Contributor

hroncok commented Jun 7, 2019

AFAIK It's only used conditionally in here:

uvloop/uvloop/loop.pyx

Lines 1055 to 1087 in 46c5e9e

if PY37:
if enabled:
self._coroutine_origin_tracking_saved_depth = (
sys.get_coroutine_origin_tracking_depth())
sys.set_coroutine_origin_tracking_depth(
DEBUG_STACK_DEPTH)
else:
sys.set_coroutine_origin_tracking_depth(
self._coroutine_origin_tracking_saved_depth)
self._coroutine_debug_set = enabled
else:
wrapper = aio_debug_wrapper
current_wrapper = sys_get_coroutine_wrapper()
if enabled:
if current_wrapper not in (None, wrapper):
_warn_with_source(
"loop.set_debug(True): cannot set debug coroutine "
"wrapper; another wrapper is already set %r" %
current_wrapper, RuntimeWarning, self)
else:
sys_set_coroutine_wrapper(wrapper)
self._coroutine_debug_set = True
else:
if current_wrapper not in (None, wrapper):
_warn_with_source(
"loop.set_debug(False): cannot unset debug coroutine "
"wrapper; another wrapper was set %r" %
current_wrapper, RuntimeWarning, self)
else:
sys_set_coroutine_wrapper(None)
self._coroutine_debug_set = False

@hroncok
Copy link
Contributor

hroncok commented Jun 10, 2019

My Cython knowledge is limited here. I wanted to do something like:

from cpython.version cimport PY_VERSION_HEX
...

IF PY_VERSION_HEX > 0x03080000:
    cdef sys_set_coroutine_wrapper = sys.set_coroutine_wrapper
    cdef sys_get_coroutine_wrapper = sys.get_coroutine_wrapper

But apparently, Cython determines this IF when cythonzing and hence it cannot work (Compile-time name 'PY_VERSION_HEX' not defined.

On the other hand, cdefs are not possible in regular if:

from cpython.version cimport PY_VERSION_HEX
...

if PY_VERSION_HEX < 0x03080000:
    cdef sys_set_coroutine_wrapper = sys.set_coroutine_wrapper
    cdef sys_get_coroutine_wrapper = sys.get_coroutine_wrapper

Gets to:

if PY_VERSION_HEX < 0x03080000:
    cdef sys_set_coroutine_wrapper = sys.set_coroutine_wrapper
        ^

uvloop/includes/stdlib.pxi:123:9: cdef statement not allowed here

Id like to make an actual C #if in there, but don't know how.

EDIT:

Trying with:

cdef sys_set_coroutine_wrapper = getattr(sys, 'set_coroutine_wrapper', None)
cdef sys_get_coroutine_wrapper = getattr(sys, 'get_coroutine_wrapper', None)

hroncok added a commit to hroncok/uvloop that referenced this issue Jun 10, 2019
The functions `sys.set_coroutine_wrapper` and `sys.get_coroutine_wrapper`,
which were provisionally added to Python 3.5 and deprecated in Python 3.7,
are removed in Python 3.8.

uvloop doesn't use them since Python 3.7, but they remained defined
in stdlib.pxi, leading to AttributeErrors on Python 3.8+.

This makes the definition fallback to None if such functions don't exist.

Fixes MagicStack#251
@hroncok
Copy link
Contributor

hroncok commented Jun 10, 2019

#253

hroncok added a commit to hroncok/uvloop that referenced this issue Jun 11, 2019
The functions `sys.set_coroutine_wrapper` and `sys.get_coroutine_wrapper`,
which were provisionally added to Python 3.5 and deprecated in Python 3.7,
are removed in Python 3.8.

uvloop doesn't use them since Python 3.7, but they remained defined
in stdlib.pxi, leading to AttributeErrors on Python 3.8+.

This makes the definition fallback to None if such functions don't exist.

Fixes MagicStack#251
@1st1 1st1 closed this as completed in #253 Jun 13, 2019
1st1 pushed a commit that referenced this issue Jun 13, 2019
The functions `sys.set_coroutine_wrapper` and `sys.get_coroutine_wrapper`,
which were provisionally added to Python 3.5 and deprecated in Python 3.7,
are removed in Python 3.8.

uvloop doesn't use them since Python 3.7, but they remained defined
in stdlib.pxi, leading to AttributeErrors on Python 3.8+.

This makes the definition fallback to None if such functions don't exist.

Fixes #251
1st1 pushed a commit that referenced this issue Jun 13, 2019
The functions `sys.set_coroutine_wrapper` and `sys.get_coroutine_wrapper`,
which were provisionally added to Python 3.5 and deprecated in Python 3.7,
are removed in Python 3.8.

uvloop doesn't use them since Python 3.7, but they remained defined
in stdlib.pxi, leading to AttributeErrors on Python 3.8+.

This makes the definition fallback to None if such functions don't exist.

Fixes #251
Olaf1022 pushed a commit to Olaf1022/Ultra-fast-asyncio that referenced this issue Aug 13, 2023
The functions `sys.set_coroutine_wrapper` and `sys.get_coroutine_wrapper`,
which were provisionally added to Python 3.5 and deprecated in Python 3.7,
are removed in Python 3.8.

uvloop doesn't use them since Python 3.7, but they remained defined
in stdlib.pxi, leading to AttributeErrors on Python 3.8+.

This makes the definition fallback to None if such functions don't exist.

Fixes MagicStack/uvloop#251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants