Fuck me on GayHub

How coroutine works internally [Drafting]

Coroutines are generalization of subroutines. they are used for cooperative multitasking where a process voluntarily yield(give away) control periodically or when idle in order to enable multiple applications to be run simultaneously. compare to thread, coroutine is context-swtich in User space by programming language or by programmer itself, but thread is managed by OS. but anyway, do you know how Python implements coroutine? or how can it yield control away and lately resume back?

A simple usage example

The Internal


coroutine in python


Stop naming your modules utils [转]

看到这篇文章的时候,内心是崩溃的,里面说的bad practice我们目前项目中都有,一个不落。就像写出了非Pythonic的代码,它没有validate Python Grammer,可以正常工作,但就是维护起来费劲。所以说在正确的前提下,我们要尽量在工程中做到这些Best Pracice说到的东西。

more >>

Gevent: patch it and pray

To speedup the IO related operations in our project, we use Gevent and patch_all in Django. but it also makes project more complicated, especially when a new maintainer trying to figure out how the multi-threading process works without knowing the patch. So Guido van Rossum once said: when you use gevent in your project, once after patch, god knows what will happen later. i.e Patch it and Pray!!! and also for other reasons, this way isn’t a Pythonic way. here in this post, let’s see how it works, why it is bad.

more >>

Django app are slow, Think Again

经常听到同事说Python服务性能不好,要去拥抱Go。但是细想,技术里面没有银弹,在某些场景下,他诚然没有编译型语言快。我们的服务都是一些I/O为主的,大部分的时间可能都是在等待网络I/O,如果换成任何一种编译型语言,难道就没有这种I/O等待了吗?再比如Instagram,Youtube,Dropbox等都在大规模使用Python,为什么人家的服务不会像蜗牛一样呢?自己的Py 服务性能差,我还能做什么呢?

more >>