zoukankan      html  css  js  c++  java
  • 单例 对类变量的修改 批修改

    #!python
    # -*- coding:utf-8 -*-
    # 目的:通过单例实现客户端调用sdk时的批处理

    # 参考:
    # {
    # Python单例模式(Singleton)的N种实现 - 知乎
    # https://zhuanlan.zhihu.com/p/37534850

    # 设计模式(Python)-单例模式 - 简书
    # https://www.jianshu.com/p/ec6589e02e2f

    # PythonDecoratorLibrary - Python Wiki
    # https://wiki.python.org/moin/PythonDecoratorLibrary

    # 3. Data model — Python 3.7.3 documentation
    # https://docs.python.org/3/reference/datamodel.html#object.__new__
    #
    # }
    # 注意:
    # 线程安全

    class SdkSingletonLoger(object):
    __instance = None
    # 存放批处理的队列 先进先出FIFO
    queue = []
    queueLength = None

    def __new__(cls, *args, **kwargs):
    if cls.__instance is None:
    cls.__instance = object.__new__(cls, *args, **kwargs)
    if cls.queueLength is None:
    cls.queueLength = 50
    if len(cls.queue) >= cls.queueLength:
    print "batchHandler"
    print len(cls.queue)
    print cls.queueLength
    return cls.__instance


    i = 0

    t = (i, 333, {})
    i += 1
    s1 = SdkSingletonLoger()
    s1.queue.append(t)
    # s1.queueLength = 2
    s1.__class__.queueLength = 2
    t = (i, 333, {})
    i += 1
    s2 = SdkSingletonLoger()
    s2.queue.append(t)

    t = (i, 333, {})
    i += 1
    s3 = SdkSingletonLoger()
    s3.queue.append(t)

    t = (i, 333, {})
    i += 1
    s4 = SdkSingletonLoger()
    s4.queue.append(t)

    dd = 9




    0
    50
    1
    2
    batchHandler
    2
    2
    batchHandler
    3
    2

    #!python
    # -*- coding:utf-8 -*-
    # 目的:通过单例实现客户端调用sdk时的批处理

    # 参考:
    # {
    # Python单例模式(Singleton)的N种实现 - 知乎
    # https://zhuanlan.zhihu.com/p/37534850

    # 设计模式(Python)-单例模式 - 简书
    # https://www.jianshu.com/p/ec6589e02e2f

    # PythonDecoratorLibrary - Python Wiki
    # https://wiki.python.org/moin/PythonDecoratorLibrary

    # 3. Data model — Python 3.7.3 documentation
    # https://docs.python.org/3/reference/datamodel.html#object.__new__
    #
    # }
    # 注意:
    # 线程安全

    class SdkSingletonLoger(object):
    __instance = None
    # 存放批处理的队列 先进先出FIFO
    queue = []
    queueLength = None

    def __new__(cls, *args, **kwargs):
    if cls.__instance is None:
    cls.__instance = object.__new__(cls, *args, **kwargs)
    if cls.queueLength is None:
    cls.queueLength = 50
    if len(cls.queue) >= cls.queueLength:
    print "batchHandler"
    print len(cls.queue)
    print cls.queueLength
    return cls.__instance


    i = 0

    t = (i, 333, {})
    i += 1
    s1 = SdkSingletonLoger()
    s1.queue.append(t)
    s1.queueLength = 2
    # s1.__class__.queueLength = 2
    t = (i, 333, {})
    i += 1
    s2 = SdkSingletonLoger()
    s2.queue.append(t)

    t = (i, 333, {})
    i += 1
    s3 = SdkSingletonLoger()
    s3.queue.append(t)

    t = (i, 333, {})
    i += 1
    s4 = SdkSingletonLoger()
    s4.queue.append(t)

    dd = 9

    0
    50
    1
    50
    2
    50
    3
    50

    Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win32

  • 相关阅读:
    计算机一些常见名词解释
    [MSF]server/capture/http_javascript_keylogger键盘记录
    .net(C#)访问Oracle数据库的几种免安装组件的对比
    C# UserControl 判断是否是设计模式中
    Python_cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)
    python 怎么启动一个外部命令程序, 并且不阻塞当前进程
    创建注记图层C# IFeatureWorkspaceAnno
    VisualSVN Server 导入已存在的库
    带您了解Oracle层次查询
    win7系统使用engine进行开发报错,“未能加载文件或程序集”
  • 原文地址:https://www.cnblogs.com/rsapaper/p/11005867.html
Copyright © 2011-2022 走看看