September 15, 2017


异步非阻塞的tornado能够让同一台服务器接受更多的连接,服务更多用户,但对于每个用户来说,原本要等10秒才出现的浏览结果,现在至少还需要10秒,甚至可能还会慢一点,因为同样的硬件,现在有更多请求被接入进来。 Read more

February 9, 2017

speed up your pyres worker

We have a queue system for async works, it is build by Pyres with Redis. It works fine if your application is small, pyres worker forks a new process before doing job, and then terminate working process, worker just waits for new job. With out application is more and more complex, every new working process spends much time on loading, the package must be loaded, the package’s dependencies must be loaded, e. Read more

April 19, 2015

exception in python

My colleague remembered that if you pass some kwargs to an Exception subclass e.g. class MyException(Exception): pass, you will get a composed message when you catch the exception and call e.message. Unitil we got nothing from one place which it should display exception’s message, python language part is implemented by C, so we downloaded python source code(2.7.9), and find these lines. static int BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) { if (! Read more

January 7, 2015

be careful python fdopen

I have got a bug when I print something to stdout, I got Bad file descriptor, it means my stdout is a bad descriptor, what?! Core code like this: logger.StreamHandler(os.fdopen(sys.stdout.fileno(), 'w', 0)), I want to a unbuffered stdout, so I reopen it by fdopen, and reset the buffer size to 0, I still also did same thing to stderr, but that is no sense, because of stderr is unbuffered normally(but in Python3, it maybe line buffered, in MacOS). Read more

December 20, 2014

quote in urllib

quote accept two arguments: a string and a safe characters. If you pass empty to quote as the second parameter, it means every characters except preserved characters will be replaced by a % leading characters, e.g. space will be replaced by %20, etc. In my project, I invoke quote like quote(params, ''), and I have imported unicode_literals, so I passed a unicode parameter to quote method. What will happen? (My project is a web project, I use Tornado frameworks, the python process will be running as a backend service. Read more

Powered by Hugo & Kiss.