migrate to gen.coroutine / compatible with python 3

This is an updated version of pull #42