首页 > 其他 > 详细

tornado singleton单例模式

时间:2014-03-16 10:32:52      阅读:476      评论:0      收藏:0      [点我收藏+]
class TOLoop:
@staticmethod
    def instance():
        """Returns a global `IOLoop` instance.

Most applications have a single, global `IOLoop` running on the
main thread. Use this method to get this instance from
another thread. To get the current thread‘s `IOLoop`, use `current()`.
"""
        if not hasattr(IOLoop, "_instance"): //避免无意义的锁定, 因为大部分调用时只是简单的返回已经创建的_instance
            with IOLoop._instance_lock:
                if not hasattr(IOLoop, "_instance"):
                    # New instance after double check
                    IOLoop._instance = IOLoop()
        return IOLoop._instance

tornado singleton单例模式,布布扣,bubuko.com

tornado singleton单例模式

原文:http://blog.csdn.net/qq550764107/article/details/21299245

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!