ijd8.COM

A simple blog for an old Ma Nong.

让Tornado 使用 ujson

Permalink

Tornado 默认使用json,但是它太慢了,我想用ujson 来代替。

在应用的入口多加下面的代码即可:

Python: ujson
1
2
3
4
5
6
import sys

try:
    sys.modules['json'] = __import__('ujson')
except ImportError:
    pass

Python: ujson
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
>>> import sys
>>> sys.modules['json'] = __import__('ujson')
>>> sys.modules['json']
<module 'ujson' from '/usr/local/lib/python2.7/dist-packages/ujson.so'>
>>> import json as a
>>> import ujson as b
>>> a == b
True
>>> a is b
True
>>> a
<module 'ujson' from '/usr/local/lib/python2.7/dist-packages/ujson.so'>
>>> b
<module 'ujson' from '/usr/local/lib/python2.7/dist-packages/ujson.so'>
>>>

Write a Comment

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.16.7 Processed in 1ms