Tornado Asynchronous Handler

前端 未结 3 875
半阙折子戏
半阙折子戏 2020-12-09 21:10

I am attempting to implement get_current_user in the RequestHandler for Tornado, but I need the call to block while waiting on the asynchronous call to my database. Decorat

3条回答
  •  旧巷少年郎
    2020-12-09 21:53

    Do a blocking database operation instead of the non blocking described above (There is a blocking mysql lib shipped with tornado).

    From the Tornado wiki page about threads and concurrency: "Do it synchronously and block the IOLoop. This is most appropriate for things like memcache and database queries that are under your control and should always be fast. If it's not fast, make it fast by adding the appropriate indexes to the database, etc."

    https://github.com/facebook/tornado/wiki/Threading-and-concurrency

提交回复
热议问题