Tornado on Python 3

237 views
Skip to first unread message

Ben Darnell

unread,
Feb 25, 2011, 12:52:21 AM2/25/11
to Tornado Mailing List
I've gotten a large portion of Tornado running on Python 3.2.  Specifically, all the unittests pass and the chat demo works.  The tests still pass under python 2.5-2.7, so I don't appear to have broken anything, but since there are so many changes I've put them in a branch for now.  


https://github.com/facebook/tornado/compare/master...python3

If you want to try it out, check out the python3 branch from github, and then run 2to3 on it.  Only python2 code is checked in; the python3 version is always generated by 2to3.  If you want to hack on it, or any other library that uses 2to3 for compatibility with both versions, you may find https://github.com/bdarnell/auto2to3 useful.  

-Ben

Brian Jones

unread,
Feb 25, 2011, 12:29:18 PM2/25/11
to python-...@googlegroups.com, Ben Darnell
Thanks, Ben -- this totally rocks. 

brian

 

-Ben



--
Brian K. Jones
My Blog          http://www.protocolostomy.com
Follow me      http://twitter.com/bkjones

Peter Bengtsson

unread,
Feb 28, 2011, 5:12:08 AM2/28/11
to python-...@googlegroups.com
This is really cool! It's nice to see that Tornado is light and modular that this is possible.

Are there any benefits to us users with using the python3 that I don't know about? 
Like, is it faster? Does it enable some cool features we couldn't use before?

Artemi Krymski

unread,
Feb 28, 2011, 5:18:17 AM2/28/11
to python-...@googlegroups.com, Peter Bengtsson
Proper unicode support is the best reason I can think of :)

Peter Bengtsson

unread,
Feb 28, 2011, 5:24:21 AM2/28/11
to Artemi Krymski, python-...@googlegroups.com
Never saw/see that as a problem with py2 thanks to Tornado getting it
right from the start. But I guess it's nice that it works without all
the extra checks and filters.

--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
fun crosstips.org

piken

unread,
Feb 28, 2011, 3:25:09 PM2/28/11
to Tornado Web Server
Have you seen any issues with the serving of binary files. I have a
file in /static/ named g.gif.

Hitting the following url: http://localhost:8888/static/g.gif

returns just the url of the gif as text as if the headers were not
correct.

While if I submit a get via telnet it appears to have worked.

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /static/g.gif HTTP/1.1

HTTP/1.1 200 OK
Content-Length: 3617
Server: TornadoServer/1.2
Last-Modified: Mon, 28 Feb 2011 12:42:31 GMT
Etag: "91dbc80081306625f5722877ac341b55aef3f08d"
Cache-Control: public
Content-Type: image/gif

GIF89a�(��[ r
z
d x#9t=7vA:s@zzz�
,� +� .� 0� 1� / 1�&6�+8�'6�4;�58�p.�v �{ �s%�8D�6E�8B�MR�QV�zM�
\`�np�xw�KW�OT�FF�SS�ZV�b[�^g�mm�lf�sr ���#


I can wget the file without issue. Just not serve it to a web client.

Other then that, I see only a few minor issues in my tests so far. For
example str values to command line args fail with a str does not have
a decode method. This is because the strings are not byte strings. For
testing I added a .encode("utf8") to the var and it worked without
issue.

A second issue I have seen so far is that curses coloring of the
logging output appears to not be working either. Having messed with it
to determine why not.

I 2to3'ed it with the following. `2to3 -w -n tornado/*.py` so not
sure if I needed another option.

Ben Darnell

unread,
Feb 28, 2011, 4:19:57 PM2/28/11
to python-...@googlegroups.com, Artemi Krymski, Peter Bengtsson
On Mon, Feb 28, 2011 at 2:18 AM, Artemi Krymski <akry...@gmail.com> wrote:
Proper unicode support is the best reason I can think of :)

"Proper" is debatable. :)  Personally I prefer a one-type solution as seen in Go (all strings are immutable byte arrays, using utf8 for all unicode text) to the two-type solution in Python and Java.  
 

On Mon, Feb 28, 2011 at 10:12 AM, Peter Bengtsson <pet...@gmail.com> wrote:
> This is really cool! It's nice to see that Tornado is light and modular that
> this is possible.
> Are there any benefits to us users with using the python3 that I don't know
> about?
> Like, is it faster? Does it enable some cool features we couldn't use
> before?

Python 3 is a somewhat cleaner language, but the main reason to use it is simply that it is "the future".  Unfortunately I don't know if it's quite ready to be "the present" yet due to the lack of support from third-party libraries, but since tornado no longer has any third-party dependencies it's possible to start experimenting with it.

-Ben

Philip Schwartz

unread,
Feb 28, 2011, 4:44:30 PM2/28/11
to python-...@googlegroups.com
Another good reason is Python 2.x being end of life with no new back ported updates.

Ben Darnell

unread,
Feb 28, 2011, 7:40:04 PM2/28/11
to python-...@googlegroups.com, piken
I've fixed the decoding of string options in the branch (this also led me to PEP 383, which demonstrates why bytes-everywhere is better than unicode-everywhere).  Both binary static files and colored log output work for me.  I'm not sure what's going on for you.  One possibility is that each version of python includes its own version of 2to3, so you should probably run the most recent (on my system with python3.2 installed via macports, it's called 2to3-3.2).  

-Ben

piken

unread,
Mar 1, 2011, 3:59:44 PM3/1/11
to Tornado Web Server
I am using 2to3-3.2 and I verified that python3.2 is doing the
running. I have a curses based ubuntu 10.04 install which color output
works fine on with python 2.6.4 installed by default, and on the apt
installed 3.1. It is the fresh 3.2 that is on the system that appears
to not work. Any ideas?
Reply all
Reply to author
Forward
0 new messages