Created
June 26, 2015 19:43
-
-
Save zroger/323d16f9e1d3d85ff592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import tornado.gen | |
import tornado.ioloop | |
@tornado.gen.coroutine | |
def coify(fn, *args): | |
raise tornado.gen.Return(fn(*args)) | |
def sync_func(name): | |
print "[%s:start] %f" % (name, time.time()) | |
time.sleep(1.0) | |
print "[%s:end] %f" % (name, time.time()) | |
@tornado.gen.coroutine | |
def test(): | |
yield([coify(sync_func, i) for i in range(10)]) | |
def main(): | |
tornado.ioloop.IOLoop().run_sync(test) | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python local/not-async.py | |
[0:start] 1435347760.540367 | |
[0:end] 1435347761.540870 | |
[1:start] 1435347761.540981 | |
[1:end] 1435347762.543574 | |
[2:start] 1435347762.543725 | |
[2:end] 1435347763.550163 | |
[3:start] 1435347763.550322 | |
[3:end] 1435347764.551568 | |
[4:start] 1435347764.551743 | |
[4:end] 1435347765.552054 | |
[5:start] 1435347765.552236 | |
[5:end] 1435347766.557174 | |
[6:start] 1435347766.557295 | |
[6:end] 1435347767.562994 | |
[7:start] 1435347767.563126 | |
[7:end] 1435347768.564621 | |
[8:start] 1435347768.564782 | |
[8:end] 1435347769.567873 | |
[9:start] 1435347769.568025 | |
[9:end] 1435347770.569853 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment