Skip to content

Support for PY37 without contextvars #138

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

Closed
wants to merge 39 commits into from

Conversation

pfreixes
Copy link
Contributor

@pfreixes pfreixes commented Apr 10, 2018

This MR aligns the uvloop code to become compatible, not production
ready, with PY37 adding the following changes:

  • Support for the new API used behind the set_debug function.
  • Adds the context=None KW to those functions that will receive it
    when uvloop runs with PY37.
  • Former asyncio.test_utils moved as an uvloop test resource.

New MR on top of that to enable contextvars should be expected.

This MR aligns the uvloop code to become compatible, not production
ready, with PY37 adding the following changes:

- Support for the new API used behind the `set_debug` function.
- Adds the `context=None` kw to those functions that will receive it
  when uvloop runs with PY37.
- Former asyncio.test_utils moved as an uvloop test resource.
@@ -362,6 +363,7 @@ def connection_lost(self, exc):
self.assertIn(excs[0].__class__,
(BrokenPipeError, ConnectionResetError))

@unittest.skipUnless(sys.version_info < (3, 7), 'Python version must be < 3.7')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have some light about why this testing is failing with 3.7 please tell me.

# so we delete refs to all modules manually (except sys)
del asyncio, concurrent, collections, errno
# so we delete refs to all modules manually (except sys, asyncio)
del concurrent, collections, errno
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removed the asyncio to avoid losing the ability to call later the asyncio.coroutines.debug_wrapper when uvloop run on an interpreter different than 3.7.

If you believe that this is a red flag, let's find another way to make the _set_coroutine_debug ready to be executed by different Python versions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep del asyncio. Otherwise uvloop would hold refs to Tasks longer than necessary (that's Cython's fault and these dels are a workaround).

You can use getattr:

cdef aio_debug_wrapper = getattr(asyncio.coroutines, 'debug_wrapper', None)

And just check if it's not None before you call it.

@pfreixes pfreixes changed the title Support for PY37 without contexvars Support for PY37 without contextvars Apr 10, 2018
@pfreixes
Copy link
Contributor Author

No way, Travis still failing one test gets frozen forever.

My gut feeling says that is because the older 3.7-dev CPython version pointing still to 3.7.0a4+. Tried to run the Travis step using Ubuntu 16.04 that must come with 3.7.0b1 [1] but looks like Travis does not have official and production-ready support for Xenial - WAT! - and keeps installing the Trusty version.

Any ideas?

[1] https://s3.amazonaws.com/travis-python-archives/binaries/ubuntu/16.04/x86_64/python-3.7-dev.tar.bz2

@pfreixes
Copy link
Contributor Author

@1st1 ^^

@1st1
Copy link
Member

1st1 commented Apr 12, 2018

Yep, I saw this PR yesterday. Will take a look tomorrow. Thanks!

@@ -22,6 +22,7 @@ if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
brew outdated automake || brew upgrade automake --with-default-names
fi

pip install --upgrade pip wheel
#pip install --upgrade pip
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting this error with the Mac environment

You should consider upgrading via the 'pip install --upgrade pip' command.
+pip install --upgrade setuptools
Traceback (most recent call last):
  File "/Users/travis/.pyenv/versions/3.6.3/bin/pip", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird. Which version of pip did it upgrade to?

@pfreixes
Copy link
Contributor Author

Finally got a green CI, not really happy with some of the patches. in any case, its something that can be used to start and obviously to get improve it. Feedback welcomed @1st1.

I know that you had some plans to give support for contextvars - the natural continuation after this PR. if you are in a rush with other stuff, I can make it.

.travis.yml Outdated
sudo: required
# Travis has removed the py37 image from their repos
# language: python
# python: "3.7"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seem to have "3.7-dev". Wouldn't that be enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I'd like to avoid using docker for running our tests, it would slow the CI down way too much.

@@ -3,7 +3,7 @@
import unittest
import sys

from asyncio import test_utils
from tests import utils as test_utils
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this "tests" import. Just move/copy the necessary functions to uvloop._testbase.

@1st1
Copy link
Member

1st1 commented Apr 16, 2018

if you are in a rush with other stuff, I can make it.

I think I'll work on it myself. My idea is to copy _asynciomodule.c to uvloop. Since it's my code I think it shouldn't take me too long to figure out how to do that correctly.

@1st1
Copy link
Member

1st1 commented Apr 16, 2018

This PR needs to land before I start working on contextvars though.

@pfreixes
Copy link
Contributor Author

@1st1 Changes applied, about the issues with Pip and Python 3.7:

Travis CI uses an older 3.7-dev image, exactly 3.7.0a4+. And the 3.7 is no longer available. Since this breaking change [1] I would say that Python 3.7 is kinda broken for Travis. I hope that the Docker solution will be a temporary one, but right now is the only way to get a functional environment running an interpreter with a version beyond the alpha 4.

The Pip issue started with the recent 10.0.0 release and the Pyenv environments [2] [3]. Take a look to the last commit, just pins the PIP version for the Mac osx environment. I hope so again that this will be just a temporary solution.

[1] travis-ci/travis-ci#9069
[2] pypa/pip#5240
[3] pyenv/pyenv#1141

@1st1
Copy link
Member

1st1 commented Apr 18, 2018

Travis CI uses an older 3.7-dev image, exactly 3.7.0a4+. And the 3.7 is no longer available. Since this breaking change [1] I would say that Python 3.7 is kinda broken for Travis. I hope that the Docker solution will be a temporary one, but right now is the only way to get a functional environment running an interpreter with a version beyond the alpha 4.

Can you try installing python 3.7 using pyenv? It worked fine for me when we tried it for https://github.com/azure/azure-functions-python-worker/

@pfreixes
Copy link
Contributor Author

pfreixes commented May 6, 2018

@1st1 I didn't manage to reproduce the same issue in local. These have been the environments that ran the tests successfully in local:

  • Docker image with Ubuntu 14.04 (trusty) with a OpenSSL 1.1 and Python 3.7 b03 from Pyenv,
  • Docker image with Ubuntu 16.04 (xenial), with Python 3.7 b03 from Pyenv.
  • Docker image with Ubuntu 16.04 (xenial), with Python 3.7 b04 (used the same one that is used by Travis)

I've tried to reproduce the local environment following this guide but looks like that the Xenial is still experimental and there is no way to download the image used by Travis, or at least I wasn't able to find it. In any case, I've opened an issue to gather some feedback from Travis

Also, I've tried to get some information running the Travis CI, no luck and also the same issue: stuck in the same test test_create_connection_3 (test_tcp.Test_AIO_TCP). Worth mentioning that the xenial environment is quite slower than the trusty one, usually takes 10 minutes more to start! and even sometimes the job finishes while the worker is still compiling the package (timeout?).

So, let's wait for some feedback from the Travis team. But I wouldn't put so many hopes on it, taking into account that for them the Xenial is still experimental and not officially supported by Travis.

@pfreixes
Copy link
Contributor Author

pfreixes commented May 6, 2018

Definitely, something is wrong with Xenial and Travis

@wumpus
Copy link

wumpus commented May 18, 2018

I am using pyenv, python 3.7.0b4 on CentOS 7, and installed this branch -- success!

It would be nice for this to get released so more people could test 3.7-dev. I personally also use Travis/Xenial for CI so the remaining bug affects me, but ...

@pfreixes
Copy link
Contributor Author

My proposal here is going for the Docker option that was proven as successful and TBH didn't add so much overhead in terms of time needed to run the tests.

Later if the xenial distro is officially supported by Travis and the tests can be run natively without using Docker its a matter of changing the configuration.

@wumpus
Copy link

wumpus commented May 20, 2018

I think we are agreeing that uvloop should not wait for TravisCI.

1st1 pushed a commit that referenced this pull request May 23, 2018
This MR aligns the uvloop code to become compatible, not production
ready, with PY37 adding the following changes:

* Support for the new API used behind the set_debug function.

* Adds the context=None KW to those functions that will receive it
  when uvloop runs with PY37.

* Former asyncio.test_utils moved as an uvloop test resource.

--
Yury: the original PR for this change is #138.  I stripped out
all the CI bits and squashed all commits by hand.  The CI
will be addressed later.
@1st1
Copy link
Member

1st1 commented May 23, 2018

Closing this one in favour of #149. The new PR is a version of this one with removed CI tweaks.

@1st1 1st1 closed this May 23, 2018
1st1 pushed a commit that referenced this pull request May 23, 2018
This MR aligns the uvloop code to become compatible, not production
ready, with PY37 adding the following changes:

* Support for the new API used behind the set_debug function.

* Adds the context=None KW to those functions that will receive it
  when uvloop runs with PY37.

* Former asyncio.test_utils moved as an uvloop test resource.

--
Yury: the original PR for this change is #138.  I stripped out
all the CI bits and squashed all commits by hand.  The CI
will be addressed later.
@pfreixes
Copy link
Contributor Author

Thanks!

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 this pull request may close these issues.

3 participants