django-websocket-redis icon indicating copy to clipboard operation
django-websocket-redis copied to clipboard

Python 3 support

Open metakermit opened this issue 10 years ago • 23 comments

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:

metakermit avatar Jul 31 '14 11:07 metakermit

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

mauricioporras avatar Jul 31 '14 20:07 mauricioporras

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

dblackdblack avatar Aug 07 '14 20:08 dblackdblack

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.

jrief avatar Aug 08 '14 05:08 jrief

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.

gygelly avatar Mar 09 '15 09:03 gygelly

+1

mstajdohar avatar Mar 26 '15 14:03 mstajdohar

+1

basilkohler avatar Apr 07 '15 15:04 basilkohler

+1

dblenkus avatar Apr 14 '15 20:04 dblenkus

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

jrief avatar Apr 14 '15 20:04 jrief

I'm working on it...

wengole avatar May 07 '15 21:05 wengole

@wengole very cool. Do you have any estimate?

Glueon avatar May 08 '15 20:05 Glueon

@Glueon see #96

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

wengole avatar May 15 '15 19:05 wengole

+1

Tritlo avatar Jun 04 '15 04:06 Tritlo

+1

jokerejoker avatar Jul 01 '15 13:07 jokerejoker

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.

jokerejoker avatar Jul 02 '15 11:07 jokerejoker

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

hgdeoro avatar Jul 22 '15 04:07 hgdeoro

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

0nkery avatar Jul 22 '15 07:07 0nkery

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

nanuxbe avatar Oct 07 '15 14:10 nanuxbe

So finally merged? Anyone tested?

Glueon avatar Oct 09 '15 19:10 Glueon

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

gitaarik avatar Oct 14 '15 19:10 gitaarik

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.

jrief avatar Oct 14 '15 20:10 jrief

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 avatar Oct 15 '15 06:10 nanuxbe

@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

nanuxbe avatar Oct 18 '15 08:10 nanuxbe

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.

malefice avatar Nov 28 '15 18:11 malefice