jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
896 stars 222 forks source link

Python 3 support #47

Open metakermit opened 10 years ago

metakermit commented 10 years ago

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:
mauricioporras commented 10 years ago

File "/home/user/websocket_env/lib/python3.2/site-packages/ws4redis/websocket.py", line 40 return u'' ^ SyntaxError: invalid syntax

dblackdblack commented 10 years ago

@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.

jrief commented 10 years ago

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.

gygelly commented 9 years ago

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.

mstajdohar commented 9 years ago

+1

basilkohler commented 9 years ago

+1

dblenkus commented 9 years ago

+1

jrief commented 9 years ago

Any volunteer? Currently I have no spare time or a project which funds this feature.

wengole commented 9 years ago

I'm working on it...

Glueon commented 9 years ago

@wengole very cool. Do you have any estimate?

wengole commented 9 years ago

@Glueon see #96

I think unfortunately, this is a no-go for now

Tritlo commented 9 years ago

+1

jokerejoker commented 9 years ago

+1

jokerejoker commented 9 years ago

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.

hgdeoro commented 9 years ago

+1, also want to mention that the latest gevent beta support Py3

0nkery commented 9 years ago

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 :).

nanuxbe commented 8 years ago

PR #113 merges @0nkery 's changes with this repo while keeping Python 2 compatibility

Glueon commented 8 years ago

So finally merged? Anyone tested?

gitaarik commented 8 years ago

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 ;)?

jrief commented 8 years ago

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.

nanuxbe commented 8 years ago

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.

nanuxbe commented 8 years ago

@gitaarik I just ran some tests and I can confirm that:

To load the fixture in the example app, run ./manage.py loaddata chatserver/fixtures/data.json

malefice commented 8 years ago

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.