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

urlopen calls on Python 3 for HTTPS are not concurrent #457

Closed
andreibica opened this issue Jan 4, 2018 · 6 comments
Closed

urlopen calls on Python 3 for HTTPS are not concurrent #457

andreibica opened this issue Jan 4, 2018 · 6 comments
Milestone

Comments

@andreibica
Copy link

I'm using eventlet (version 0.20.1) with Python 3.5.4 and its look like calling multiple urlopen in parallel is not working. Only one urlopen is executed at once.

Here is the provided urlopen example which was modified for Python 3 and it shows the issue.
Each request takes about one second, but doing them in parallel should take also around 1 second.
Still, the the total time is the sum required for each request.

import eventlet
from eventlet.green.urllib.request import urlopen

urls = [
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
    "https://httpstat.us/200?sleep=1000",
]


def fetch(url):
    print("opening", url)
    body = urlopen(url).read()
    print("done with", url)
    return url, body


pool = eventlet.GreenPool(200)
for url, body in pool.imap(fetch, urls):
    print("got body from", url, "of length", len(body))
@andreibica
Copy link
Author

It looks like the problem appears only when using HTTPS.
For HTTP urlopen calls are concurent.

@andreibica andreibica changed the title urlopen on Python 3 not parallel urlopen calls on Python 3 for HTTPS are not concurrent Jan 12, 2018
@temoto
Copy link
Member

temoto commented Jan 12, 2018

Thanks, I was confused about this bug report. Does it work with monkey_patch() ?

@andreibica
Copy link
Author

It works with monkey_patch(), but I'm not sure if it is ok to apply monkey_patch on my code since it also contains code which is not eventlet based. I assume that monkey_patch affects all Python code running in the Python interpreter.

@temoto temoto added this to the 0.23 milestone Jan 16, 2018
@temoto
Copy link
Member

temoto commented Jan 16, 2018

Yes, it contains code that is not eventlet based. For example, urllib from standard Python library.

Please, try this patch.

pip install https://github.com/eventlet/eventlet/archive/5739f73ce8c9af9cab128dc1258f2c6b1ee56cbb.zip

@andreibica
Copy link
Author

The patch is working. The HTTPS requests are now concurrent without monkey_patch.

@temoto
Copy link
Member

temoto commented Jan 16, 2018

@andreibica thanks for testing.

And thank you very much for using from eventlet.green imports.

Fix will be merged into master when I construct a test case.

@temoto temoto modified the milestones: 0.23, 0.24 May 8, 2018
@temoto temoto modified the milestones: 0.24, 0.25 Aug 3, 2018
temoto added a commit that referenced this issue Dec 6, 2022
temoto added a commit that referenced this issue Dec 6, 2022
temoto added a commit that referenced this issue Dec 6, 2022
temoto added a commit that referenced this issue Dec 6, 2022
temoto added a commit that referenced this issue Dec 6, 2022
@temoto temoto closed this as completed in b034167 Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants