eventlet icon indicating copy to clipboard operation
eventlet copied to clipboard

>=0.25.0 with Python 2.7: Importing eventlet.green.urllib breaks urlparse from the future library

Open jdominguez-wish opened this issue 4 years ago • 4 comments

Environment: Docker container built from python:2.7-slim-buster (Debian variant). Also verified on my own computer running Ubuntu 20.04.1 LTS eventlet version: >= 0.25.0 (I verified that the bug does not occur with ==0.24.1 but does occur with ==0.25.0. I also verified that it occurs with the latest master.) Output from uname -a: Linux c9efdf963b14 5.4.0-59-generic #65-Ubuntu SMP Thu Dec 10 12:01:51 UTC 2020 x86_64 GNU/Linux Python version: 2.7.18 pip freeze:

dnspython==1.16.0
eventlet==0.30.0
future==0.18.2
greenlet==1.0.0
monotonic==1.5
six==1.15.0

I have searched the previous issues and found no mention of this issue.

Description: In Python 2, we use a library which is designed to work across both Python 2 and Python 3 for now. It uses future.standard_library.install_aliases to do this. However, when using this library in tandem with eventlet, and importing eventlet.green.urllib, the aliases no longer work and the library fails with an ImportError.

Steps to reproduce: Run the following MWE:

from future.standard_library import install_aliases
install_aliases()
import eventlet.green.urllib
from urllib.parse import urlparse # ImportError: No module named parse

Please let me know if more information or clarification is required! I tried to investigate this as thoroughly as I could but it's certainly possible that I missed something. Also, I saw that Python 2.7 support is deprecated (understandably so), so if this bug is deemed not worth fixing, it might be worth adding a notice to the affected versions.

jdominguez-wish avatar Jan 19 '21 08:01 jdominguez-wish

It's correct, there is no urllib.parse in Python2.

temoto avatar Jan 22 '21 15:01 temoto

Hi, thanks for your reply! I understand that usually that is the case. However, install_aliases is supposed to add an alias to urlparse so that one can write code that works on both Python 2 and Python 3. For example, the following modified snippet runs fine in Python 2 (I should have mentioned this above, sorry):

from future.standard_library import install_aliases
install_aliases()
#import eventlet.green.urllib
from urllib.parse import urlparse

jdominguez-wish avatar Jan 22 '21 21:01 jdominguez-wish

Yes, it seems like a bug with Eventlet. I don't have time to dig deeper, in part because we've deprecated Python2 support.

My best suggestion is import urllib from six, it's known to work with eventlet patching.

temoto avatar Jan 26 '21 18:01 temoto

I see, thanks for taking the time to read the issue nonetheless. I think we'll stick with the older version of eventlet mentioned above for now (given that the relevant code is contained inside a dependency), until (hopefully) upgrading to Python 3.

jdominguez-wish avatar Jan 26 '21 20:01 jdominguez-wish