django-websocket-redis
django-websocket-redis copied to clipboard
Python 3 support
Can we get Python 3 support, please? Now that gevent experimentally supports Python 3 on the master branch, it might be viable. Currently, I see the basic incompatibilities that would work in Python 2.7 without using future or six if fixed:
except IOError, e:
File "/home/user/websocket_env/lib/python3.2/site-packages/ws4redis/websocket.py", line 40 return u'' ^ SyntaxError: invalid syntax
@mauricioporras Python 3.4 re-introduced the ability to prefix strings with u
in order to make this class of syntax errors go away. Adding u
doesn't do anything, but it isn't a syntax error either. Try using Python 3.4.
As I wrote in another issue, this websocket.py
file was pilfered from another project. It currently is the only part, which I was unable to port to Python-3.3, see https://bitbucket.org/Jeffrey/gevent-websocket/issue/54/python-3-support for details.
Any chance of revisiting this? how about asking the gevent-websocket author again? He gave the lack of python 3 support in gevent as the reason he didn't pursue it, and that should no longer be an issue.
+1
+1
+1
Any volunteer? Currently I have no spare time or a project which funds this feature.
I'm working on it...
@wengole very cool. Do you have any estimate?
@Glueon see #96
I think unfortunately, this is a no-go for now
+1
+1
I have made a patch that roughly gives PY3 support https://github.com/datanordic/django-websocket-redis/commit/5db89226ffc5c54c662b60c6c67d5cd36790ebed . Anyone care to check it out? :) The code is not at all tested on PY2 so further patching, in this regard, might be needed before a pull request can be made.
+1, also want to mention that the latest gevent beta support Py3
https://github.com/0nkery/django-websocket-redis3
Try it. This fork doesn't support PY2. I have had fixed both obvious and non-obvious bugs, but there is still room for them :).
PR #113 merges @0nkery 's changes with this repo while keeping Python 2 compatibility
So finally merged? Anyone tested?
Seems to work for me! :)
I cloned https://github.com/jrief/django-websocket-redis and created a virtualenv with pyhton3:
virtualenv --python=python3 env
And installed these requirements (instead of the ones in examples/requirements.txt
) in it:
Cython==0.23.4
Django==1.8.5
backports.ssl-match-hostname==3.4.0.2
django-nose==1.4.1
django-redis-sessions==0.5.0
git+git://github.com/gevent/gevent.git#egg=gevent
git+git://github.com/jrief/django-websocket-redis.git@master
greenlet==0.4.9
nose==1.3.7
redis==2.10.3
requests==2.7.0
six==1.10.0
websocket-client==0.20.0
And when trying the example:
(env)~/dev/ws4r-test/src/examples $ ./manage.py runserver
The example chat app seems to work fine, at least, the broadcast chat, the user and group chat give an TypeError
, but that's probably because this example chat app hasn't been made Python 3 compatible. Just using websockets seems to work fine. Haven't run into any issues yet, though we haven't used it much yet.
Still, it's very nice support is there! We just started using websockets and we're on Python 3 with our Django installation, so thanks a lot for the pull request and merge @0nkery & @nanuxbe!
About the pip requirements: at time of writing I also needed gevent's git repo because it also just got Python 3 support, and for this you need Cython because gevent needs that to build (not necessary for the regular pip package). So installation takes quite some time longer because of Cython. But by the time you're done developing your websockets and putting it up for production these patches should all be in the pip repository, right ;)?
I'm happy to hear that! Currently I have no time to work on ws4redis, therefore I'm very pleased on pull requests for enhancements.
I have actually not tried the example chat app (I focused on the tests), i'll double-check the app and update it for python 3.
If you look at the tests, the syntax to use with python3 is a bit different as you have to .decode()
the replies you get from the ws in python. If I have time I'll see if I can integrate that in the lib itself to avoid the different syntaxes.
As far as the requirements are concerned I had no trouble with gevent from pypi but I'll double-check too. I'll probably do that this weekend.
@gitaarik I just ran some tests and I can confirm that:
- you don't need to pull gevent from github, 1.0.2 (from the example app requirements.txt) works fine with python 3.4 and 3.3
- user and group chat from the test app both work fine but you need to load the fixtures first or create yourself a couple of users to test with.
To load the fixture in the example app, run ./manage.py loaddata chatserver/fixtures/data.json
Confirmed! Using the requirements listed in a previous post works if you use the ./manage.py runserver
to test, and so far it works great with Python 3.
I encountered some issues though when attempting to use uwsgi as a standalone server as proposed in this section of the docs. After several print statements, I found out that the Websocket
object used when using the uwsgi command is different from the one used by ./manage.py runserver
.
Long story short, bytestrings are being passed into the RedisMessage
wrapper at this specific line, but the RedisMessage
wrapper only handles str
or list
types causing all websocket messages sent to be discarded.
PR #122 will address that, and so far, everything is working.