Skip to content

Introduce grequests error report in django project #147

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
sonion028 opened this issue Nov 14, 2020 · 4 comments
Closed

Introduce grequests error report in django project #147

sonion028 opened this issue Nov 14, 2020 · 4 comments
Labels
🙉🙈🙊 gevent some issue likely caused by gevent, not necessarily grequests question

Comments

@sonion028
Copy link

Introduce grequests error report in django project:

/usr/local/python3/lib/python3.6/site-packages/grequests.py:22:
MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See gevent/gevent#1016. Modules that had direct imports (NOT patched): ['urllib3.util.ssl_ (/usr/local/python3/lib/python3.6/site-packages/urllib3/util/ssl_.py)', 'urllib3.util (/usr/local/python3/lib/python3.6/site-packages/urllib3/util/init.py)'].
curious_george.patch_all(thread=False, select=False)

May I ask what is the reason?

Package Version


alipay-sdk-python 3.3.398
amqp 2.5.2
asgiref 3.2.7
asn1crypto 1.3.0
billiard 3.6.3.0
celery 4.4.2
certifi 2020.4.5.1
cffi 1.14.0
chardet 3.0.4
crypto 1.4.1
cryptography 2.9
Django 3.0.5
django-celery-results 1.1.2
django-cors-headers 3.4.0
dnspython 1.16.0
dwebsocket 0.5.12
eventlet 0.29.1
gevent 20.9.0
greenlet 0.4.17
grequests 0.6.0
idna 2.9
importlib-metadata 1.6.0
kombu 4.6.8
monotonic 1.5
more-itertools 8.2.0
Naked 0.1.31
optionaldict 0.1.1
pip 20.2.4
pyasn1 0.4.8
pycparser 2.20
pycrypto 2.6.1
pycryptodomex 3.9.4
PyJWT 1.7.1
PyMySQL 0.9.3
pyOpenSSL 19.1.0
python-alipay-sdk 2.0.1
python-dateutil 2.8.1
pytz 2019.3
PyYAML 5.3.1
requests 2.25.0
rsa 4.0
setuptools 46.1.3
shellescape 3.8.1
six 1.14.0
sqlparse 0.3.1
urllib3 1.25.9
uWSGI 2.0.19.1
vine 1.3.0
wechatpy 1.8.14
xmltodict 0.12.0
xpinyin 0.5.7
zipp 3.1.0
zope.event 4.5.0
zope.interface 5.2.0

@spyoungtech
Copy link
Owner

spyoungtech commented Dec 9, 2020

This warning comes from gevent -- This happens if you import the ssl module (or import any other library that, at some point, imports ssl) before importing grequests. The warning was introduced in a recent version of gevent

For example:

# bad
import requests
import grequests

This raises the warning you see. It's a good warning, as this scenario will also lead to misbehavior in using grequests.

Instead, you want to try to make sure you import grequests first before other modules that use patched libraries.

#  OK
import grequests
import requests

Key takeaway: make sure that grequests is imported first.

It's also worth mentioning that grequests can have conflicts with other packages that use gevent (or even modules that gevent patches, in some cases). uWSGI could fall into this category, particularly if configured to use gevent. Though, it's not clear that's the case here.

See also: gevent/gevent#1235

@spyoungtech spyoungtech added 🙉🙈🙊 gevent some issue likely caused by gevent, not necessarily grequests question labels Dec 9, 2020
@sonion028
Copy link
Author

sonion028 commented Dec 11, 2020

Does this warning need to be dealt with?
Other modules are also using gevent, there is always one to import first, right?

@spyoungtech
Copy link
Owner

Unfortunately, I'm not sure it's possible to say. Really, it depends...

It's hard to predict whether or not the monkey patching between libraries will be compatible... For better or worse, grequests uses gevent.monkey.patch_all(thread=False, select=False)

This may or may not be compatible with how other libraries expect things to be patched.

That said, grequests is generally intended to be used in a standalone fashion. It's best to not use it with other packages that also use gevent or rely on libraries that are patched by gevent.monkey.patch_all(thread=False, select=False) as they may not behave as expected.

@Sdamuu
Copy link

Sdamuu commented Aug 30, 2021

This warning comes from gevent -- This happens if you import the ssl module (or import any other library that, at some point, imports ssl) before importing grequests. The warning was introduced in a recent version of gevent

For example:

# bad
import requests
import grequests

This raises the warning you see. It's a good warning, as this scenario will also lead to misbehavior in using grequests.

Instead, you want to try to make sure you import grequests first before other modules that use patched libraries.

#  OK
import grequests
import requests

Key takeaway: make sure that grequests is imported first.

It's also worth mentioning that grequests can have conflicts with other packages that use gevent (or even modules that gevent patches, in some cases). uWSGI could fall into this category, particularly if configured to use gevent. Though, it's not clear that's the case here.

See also: gevent/gevent#1235

Thanks!!! It works 😁😁😁

@spyoungtech spyoungtech closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙉🙈🙊 gevent some issue likely caused by gevent, not necessarily grequests question
Projects
None yet
Development

No branches or pull requests

3 participants