noisyboiler / wampy

Websocket RPC and Pub/Sub for Python applications and microservices
Mozilla Public License 2.0
127 stars 24 forks source link

MonkeyPatchWarning #81

Closed EmilyRagan closed 5 years ago

EmilyRagan commented 5 years ago

When importing from wampy (tried from wampy.peers import Client and import wampy) both when trying to run a file and when in the Python REPL, I get the following error (I broke it into several lines to make it a bit more readable):

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wampy/__init__.py:28: 
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 https://github.com/gevent/gevent/issues/1016. 
Modules that had direct imports (NOT patched):
['eventlet.green.ssl (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/eventlet/green/ssl.py)']. 
Subclasses (NOT patched): ["<class 'eventlet.green.ssl.GreenSSLContext'>"].
  gevent.monkey.patch_all()

Python v3.7.1

noisyboiler commented 5 years ago

Hi @EmilyRagan thanks for raising this. yep, I see the problem. will address it in the next release. Simon

noisyboiler commented 5 years ago

i think this makes sense if you have imported wampy after importing a bunch of stuff yourself in a script. i believe that once it's done the first time, following calls are a no-op. It's worth trying doing the monkey patch at the very top of your script (or commands) and seeing if the error disappears when subsequently importing wampy? i.e.

import gevent.monkey
gevent.monkey.patch_all()

This returns True on the first call, then nothing thereafter.

If this fixes your error messages then it's time for me to update the README with some guidelines on how to use wampy in a script.

Look forward to hearing back from you.

Thanks for your interest.

Simon

noisyboiler commented 5 years ago

hiya @EmilyRagan wampy can't do the monkey business any earlier, so i am confident that the above advice to you is correct. re-open this if you have more ways to recreate this issue, or email me directly if you like. Once again, thanks for your interest! I'm really pleased that you're using wampy. Simon