• mysql的链接单例模式和线程池的优劣性


    单例模式代码

    mysql_test.py

    from functools import wraps
    import pymysql
    def single(cls):
        """实现类的单例模式"""
        instance_dict = dict()
        @wraps(cls)
        def single_instance(*args,**kwargs):
            if cls not in instance_dict:
                instance_dict[cls] = cls(*args,**kwargs)
            return instance_dict[cls]
        return single_instance
    
    @single
    class PyMySQLTest(object):
        def __init__(self,db_name):
            self.coon = None
            self.cursor = None
            self.db_name = db_name
            try:
                self.coon = pymysql.connect(host="xx",port=xx,user="xx",password="xx",database=self.db_name,charset="utf8")
                self.cursor = self.coon.cursor()
            except Exception as e:
                raise e
    
        def get_all(self):
            sql = "select cow_number from cow_info where isdelete=0"
            self.cursor.execute(sql)
            result = self.cursor.fetchall()
            print(result)

    test_code.py

    from single_pool.test_mysql import mysql_test,mysql_pool_test
    from threading import Thread
    import threading
    import time
    
    
    single_instance = mysql_test.PyMySQLTest("cattle")
    # lock = threading.Lock()
    def test():
        global count
        print(id(single_instance))
        print("
    ")
        single_instance.get_all()
    
    if __name__ == '__main__':
        start_time = time.time()
    # 创建100个线程链接实例,测试获取数据
        for i in range(10):
            t = Thread(target=test)
            t.start()
        end_time = time.time()
        print(end_time-start_time)

    输出结果:

    40899976
    
    
    40899976
    
    
    40899976
    
    
    40899976
    
    
    40899976
    
    
    40899976
    
    
    40899976
    
    
    40899976
    
    
    40899976
    
    
    40899976
    
    
    0.0020003318786621094

    报错结果

    pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
    错误原因:
    一:MySQL持久化链接保持时间为8小时(28800秒),过期后断开连。如果数据库没有新建连接,则会报此错。我这里肯定达不到这个条件 二:因为mysql有一个默认的connect_timeout时间,一旦超过,会自动关闭连接。看看myql和pymysql的文档。# TODO pymysql.err.InternalError: Packet sequence number wrong
    - got 110 expected 2 错误原因:
    一:使用了多线程,多线程共享了同一个数据库连接,但每个execute前没有加上互斥锁 AttributeError:
    'NoneType' object has no attribute 'read'
    错误原因:不详

    给代码加上互斥锁看看情况

    from single_pool.test_mysql import mysql_test,mysql_pool_test
    from threading import Thread
    import threading
    import time
    
    
    single_instance = mysql_test.PyMySQLTest("cattle")
    lock = threading.Lock()
    def test(l):
        single_instance.get_all(l)
    
    if __name__ == '__main__':
        start_time = time.time()
    # 创建100个线程链接实例,测试获取数据
        for i in range(10):
            t = Thread(target=test,args=(lock,))
            t.start()
        end_time = time.time()
        print(end_time-start_time)
        def get_all(self,l):
            sql = "select cow_number from cow_info where isdelete=0"
            l.acquire()
            self.cursor.execute(sql)
            l.release()
            result = self.cursor.fetchall()
            print(result)

    输出结果

    0.002000093460083008
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))
    (('1002',), ('1005',), ('2007',), ('3001',), ('3004',), ('868201803000700',), ('868201803000704',), ('868201803000702',), ('868201803000696',), ('868201803000701',), ('868201803000697',), ('868201803000699',), ('868201803000689',), ('868201803000682',), ('868201803000695',), ('868201803000688',), ('868201803000681',), ('868201803000703',), ('868201803000674',), ('868201803000651',), ('180078',), ('180025',), ('130558',), ('160080',), ('160090',), ('170071',), ('170087',), ('170099',), ('170135',), ('150153',), ('160073',), ('170083',), ('150037',), ('150249',), ('160168',), ('160002',), ('170080',), ('140157',), ('160225',), ('140161',), ('140588',), ('160804',), ('140170',), ('160068',), ('16411',), ('160527',), ('180070',), ('180026',), ('180034',), ('180004',), ('1003',), ('130653',), ('160170',), ('180753',), ('180795',), ('180698',), ('180675',), ('20191001',), ('20191002',), ('140680',), ('170058',), ('170159',), ('160059',), ('170095',), ('150092',), ('20200221',), ('20200224',), ('20200226',), ('130739',), ('160169',), ('150641',), ('160829',), ('20200301',), ('2020030111',), ('202003011112',), ('170151',), ('150350',), ('180007',), ('110615',), ('160250',), ('170107',), ('150039',), ('170153',), ('110926',), ('170136',), ('160097',), ('160423',), ('160329',), ('170069',), ('170152',), ('140738',), ('110301',), ('170092',), ('160098',), ('150090',), ('180748',))

    然后将线程数量增加到100个,看结果,没问题,200个,300个也没有问题。

    连接池代码

    class PyMySQLTest(object):
        def __init__(self,db_name):
            self.db_name = db_name
            try:
                self.pool = PooledDB(
                    creator=pymysql, # 连接对象或者符合DB-API 2的数据库模块
                    maxconnections=10, # 通常允许的最大连接数,0或None表示任意数量的连接
                    mincached=5, # 池中空闲连接的数据,值为0表示启动时未建立连接
                    maxcached=0, # 池中空闲连接的最大数目,即池的大小,0 None两个值表示池大小不受限制
                    maxshared=3, # 最大共享连接数,0或None表示所有连接都是专用的,当达到此最大数量时,如果请求共享,则共享
                    blocking=True, # 制定了超过最大连接数量时的行为,如果为True,超过时,阻塞等待连接减少,否则报错
                    maxusage=None, # 单个连接的最大重用次数,0或None表示无限重用,当达到连接的最大使用次数时,连接将自动重置即关闭连接后再打开
                    setsession=[], # 可用于准备的sql命令的可选列表会话,例如设置datestyle,设置时区等
                    ping=0, # 确定何时使用ping进行检测连接,0或者None表示从不检测,1表示从池中获取时检测,2表示创建光标时检测,4表示执行查询时检测,7表示始终检测,args,kwargs:应传递给创建者的参数
                    host = "xx",
                    port = xx,
                    user = "xx",
                    password = "xx",
                    database = self.db_name,
                    charset = "utf8"
                )
            except Exception as e:
                raise e
    
        def connect(self):
            self.coon = self.pool.connection()
            self.cursor = self.coon.cursor(cursor=pymysql.cursors.DictCursor)
            return self.cursor
    
        def get_all(self):
            cursor = self.connect()
            sql = "select cow_number from cow_info where isdelete=0"
            cursor.execute(sql)
            result = cursor.fetchall()
            print(result)
    from single_pool.test_mysql import mysql_test,mysql_pool_test
    from threading import Thread
    import threading
    import time
    
    
    single_instance = mysql_pool_test.PyMySQLTest("cattle")
    def test():
        single_instance.get_all()
    
    if __name__ == '__main__':
        start_time = time.time()
    # 创建100个线程链接实例,测试获取数据
        for i in range(10):
            t = Thread(target=test)
            t.start()
        end_time = time.time()
        print(end_time-start_time)

    输出结果

    E:pythonpython.exe F:/pycharm测试功能文件夹/single_pool/test_code.py
    0.002000093460083008
    Exception in thread Thread-1:
    Traceback (most recent call last):
      File "E:pythonlib	hreading.py", line 926, in _bootstrap_inner
        self.run()
      File "E:pythonlib	hreading.py", line 870, in run
        self._target(*self._args, **self._kwargs)
      File "F:/pycharm测试功能文件夹/single_pool/test_code.py", line 10, in test
        single_instance.get_all()
      File "F:pycharm测试功能文件夹single_pool	est_mysqlmysql_pool_test.py", line 47, in get_all
        cursor.execute(sql)
      File "E:pythonlibsite-packagesDBUtilsSteadyDB.py", line 605, in tough_method
        result = method(*args, **kwargs)  # try to execute
      File "E:pythonlibsite-packagespymysqlcursors.py", line 170, in execute
        result = self._query(query)
      File "E:pythonlibsite-packagespymysqlcursors.py", line 328, in _query
        conn.query(q)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 517, in query
        self._affected_rows = self._read_query_result(unbuffered=unbuffered)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 732, in _read_query_result
        result.read()
      File "E:pythonlibsite-packagespymysqlconnections.py", line 1075, in read
        first_packet = self.connection._read_packet()
      File "E:pythonlibsite-packagespymysqlconnections.py", line 674, in _read_packet
        recv_data = self._read_bytes(bytes_to_read)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 691, in _read_bytes
        data = self._rfile.read(num_bytes)
    AttributeError: 'NoneType' object has no attribute 'read'
    
    [{'cow_number': '1002'}, {'cow_number': '1005'}, {'cow_number': '2007'}, {'cow_number': '3001'}, {'cow_number': '3004'}, {'cow_number': '868201803000700'}, {'cow_number': '868201803000704'}, {'cow_number': '868201803000702'}, {'cow_number': '868201803000696'}, {'cow_number': '868201803000701'}, {'cow_number': '868201803000697'}, {'cow_number': '868201803000699'}, {'cow_number': '868201803000689'}, {'cow_number': '868201803000682'}, {'cow_number': '868201803000695'}, {'cow_number': '868201803000688'}, {'cow_number': '868201803000681'}, {'cow_number': '868201803000703'}, {'cow_number': '868201803000674'}, {'cow_number': '868201803000651'}, {'cow_number': '180078'}, {'cow_number': '180025'}, {'cow_number': '130558'}, {'cow_number': '160080'}, {'cow_number': '160090'}, {'cow_number': '170071'}, {'cow_number': '170087'}, {'cow_number': '170099'}, {'cow_number': '170135'}, {'cow_number': '150153'}, {'cow_number': '160073'}, {'cow_number': '170083'}, {'cow_number': '150037'}, {'cow_number': '150249'}, {'cow_number': '160168'}, {'cow_number': '160002'}, {'cow_number': '170080'}, {'cow_number': '140157'}, {'cow_number': '160225'}, {'cow_number': '140161'}, {'cow_number': '140588'}, {'cow_number': '160804'}, {'cow_number': '140170'}, {'cow_number': '160068'}, {'cow_number': '16411'}, {'cow_number': '160527'}, {'cow_number': '180070'}, {'cow_number': '180026'}, {'cow_number': '180034'}, {'cow_number': '180004'}, {'cow_number': '1003'}, {'cow_number': '130653'}, {'cow_number': '160170'}, {'cow_number': '180753'}, {'cow_number': '180795'}, {'cow_number': '180698'}, {'cow_number': '180675'}, {'cow_number': '20191001'}, {'cow_number': '20191002'}, {'cow_number': '140680'}, {'cow_number': '170058'}, {'cow_number': '170159'}, {'cow_number': '160059'}, {'cow_number': '170095'}, {'cow_number': '150092'}, {'cow_number': '20200221'}, {'cow_number': '20200224'}, {'cow_number': '20200226'}, {'cow_number': '130739'}, {'cow_number': '160169'}, {'cow_number': '150641'}, {'cow_number': '160829'}, {'cow_number': '20200301'}, {'cow_number': '2020030111'}, {'cow_number': '202003011112'}, {'cow_number': '170151'}, {'cow_number': '150350'}, {'cow_number': '180007'}, {'cow_number': '110615'}, {'cow_number': '160250'}, {'cow_number': '170107'}, {'cow_number': '150039'}, {'cow_number': '170153'}, {'cow_number': '110926'}, {'cow_number': '170136'}, {'cow_number': '160097'}, {'cow_number': '160423'}, {'cow_number': '160329'}, {'cow_number': '170069'}, {'cow_number': '170152'}, {'cow_number': '140738'}, {'cow_number': '110301'}, {'cow_number': '170092'}, {'cow_number': '160098'}, {'cow_number': '150090'}, {'cow_number': '180748'}]
    [{'cow_number': '1002'}, {'cow_number': '1005'}, {'cow_number': '2007'}, {'cow_number': '3001'}, {'cow_number': '3004'}, {'cow_number': '868201803000700'}, {'cow_number': '868201803000704'}, {'cow_number': '868201803000702'}, {'cow_number': '868201803000696'}, {'cow_number': '868201803000701'}, {'cow_number': '868201803000697'}, {'cow_number': '868201803000699'}, {'cow_number': '868201803000689'}, {'cow_number': '868201803000682'}, {'cow_number': '868201803000695'}, {'cow_number': '868201803000688'}, {'cow_number': '868201803000681'}, {'cow_number': '868201803000703'}, {'cow_number': '868201803000674'}, {'cow_number': '868201803000651'}, {'cow_number': '180078'}, {'cow_number': '180025'}, {'cow_number': '130558'}, {'cow_number': '160080'}, {'cow_number': '160090'}, {'cow_number': '170071'}, {'cow_number': '170087'}, {'cow_number': '170099'}, {'cow_number': '170135'}, {'cow_number': '150153'}, {'cow_number': '160073'}, {'cow_number': '170083'}, {'cow_number': '150037'}, {'cow_number': '150249'}, {'cow_number': '160168'}, {'cow_number': '160002'}, {'cow_number': '170080'}, {'cow_number': '140157'}, {'cow_number': '160225'}, {'cow_number': '140161'}, {'cow_number': '140588'}, {'cow_number': '160804'}, {'cow_number': '140170'}, {'cow_number': '160068'}, {'cow_number': '16411'}, {'cow_number': '160527'}, {'cow_number': '180070'}, {'cow_number': '180026'}, {'cow_number': '180034'}, {'cow_number': '180004'}, {'cow_number': '1003'}, {'cow_number': '130653'}, {'cow_number': '160170'}, {'cow_number': '180753'}, {'cow_number': '180795'}, {'cow_number': '180698'}, {'cow_number': '180675'}, {'cow_number': '20191001'}, {'cow_number': '20191002'}, {'cow_number': '140680'}, {'cow_number': '170058'}, {'cow_number': '170159'}, {'cow_number': '160059'}, {'cow_number': '170095'}, {'cow_number': '150092'}, {'cow_number': '20200221'}, {'cow_number': '20200224'}, {'cow_number': '20200226'}, {'cow_number': '130739'}, {'cow_number': '160169'}, {'cow_number': '150641'}, {'cow_number': '160829'}, {'cow_number': '20200301'}, {'cow_number': '2020030111'}, {'cow_number': '202003011112'}, {'cow_number': '170151'}, {'cow_number': '150350'}, {'cow_number': '180007'}, {'cow_number': '110615'}, {'cow_number': '160250'}, {'cow_number': '170107'}, {'cow_number': '150039'}, {'cow_number': '170153'}, {'cow_number': '110926'}, {'cow_number': '170136'}, {'cow_number': '160097'}, {'cow_number': '160423'}, {'cow_number': '160329'}, {'cow_number': '170069'}, {'cow_number': '170152'}, {'cow_number': '140738'}, {'cow_number': '110301'}, {'cow_number': '170092'}, {'cow_number': '160098'}, {'cow_number': '150090'}, {'cow_number': '180748'}]
    [{'cow_number': '1002'}, {'cow_number': '1005'}, {'cow_number': '2007'}, {'cow_number': '3001'}, {'cow_number': '3004'}, {'cow_number': '868201803000700'}, {'cow_number': '868201803000704'}, {'cow_number': '868201803000702'}, {'cow_number': '868201803000696'}, {'cow_number': '868201803000701'}, {'cow_number': '868201803000697'}, {'cow_number': '868201803000699'}, {'cow_number': '868201803000689'}, {'cow_number': '868201803000682'}, {'cow_number': '868201803000695'}, {'cow_number': '868201803000688'}, {'cow_number': '868201803000681'}, {'cow_number': '868201803000703'}, {'cow_number': '868201803000674'}, {'cow_number': '868201803000651'}, {'cow_number': '180078'}, {'cow_number': '180025'}, {'cow_number': '130558'}, {'cow_number': '160080'}, {'cow_number': '160090'}, {'cow_number': '170071'}, {'cow_number': '170087'}, {'cow_number': '170099'}, {'cow_number': '170135'}, {'cow_number': '150153'}, {'cow_number': '160073'}, {'cow_number': '170083'}, {'cow_number': '150037'}, {'cow_number': '150249'}, {'cow_number': '160168'}, {'cow_number': '160002'}, {'cow_number': '170080'}, {'cow_number': '140157'}, {'cow_number': '160225'}, {'cow_number': '140161'}, {'cow_number': '140588'}, {'cow_number': '160804'}, {'cow_number': '140170'}, {'cow_number': '160068'}, {'cow_number': '16411'}, {'cow_number': '160527'}, {'cow_number': '180070'}, {'cow_number': '180026'}, {'cow_number': '180034'}, {'cow_number': '180004'}, {'cow_number': '1003'}, {'cow_number': '130653'}, {'cow_number': '160170'}, {'cow_number': '180753'}, {'cow_number': '180795'}, {'cow_number': '180698'}, {'cow_number': '180675'}, {'cow_number': '20191001'}, {'cow_number': '20191002'}, {'cow_number': '140680'}, {'cow_number': '170058'}, {'cow_number': '170159'}, {'cow_number': '160059'}, {'cow_number': '170095'}, {'cow_number': '150092'}, {'cow_number': '20200221'}, {'cow_number': '20200224'}, {'cow_number': '20200226'}, {'cow_number': '130739'}, {'cow_number': '160169'}, {'cow_number': '150641'}, {'cow_number': '160829'}, {'cow_number': '20200301'}, {'cow_number': '2020030111'}, {'cow_number': '202003011112'}, {'cow_number': '170151'}, {'cow_number': '150350'}, {'cow_number': '180007'}, {'cow_number': '110615'}, {'cow_number': '160250'}, {'cow_number': '170107'}, {'cow_number': '150039'}, {'cow_number': '170153'}, {'cow_number': '110926'}, {'cow_number': '170136'}, {'cow_number': '160097'}, {'cow_number': '160423'}, {'cow_number': '160329'}, {'cow_number': '170069'}, {'cow_number': '170152'}, {'cow_number': '140738'}, {'cow_number': '110301'}, {'cow_number': '170092'}, {'cow_number': '160098'}, {'cow_number': '150090'}, {'cow_number': '180748'}]
    [{'cow_number': '1002'}, {'cow_number': '1005'}, {'cow_number': '2007'}, {'cow_number': '3001'}, {'cow_number': '3004'}, {'cow_number': '868201803000700'}, {'cow_number': '868201803000704'}, {'cow_number': '868201803000702'}, {'cow_number': '868201803000696'}, {'cow_number': '868201803000701'}, {'cow_number': '868201803000697'}, {'cow_number': '868201803000699'}, {'cow_number': '868201803000689'}, {'cow_number': '868201803000682'}, {'cow_number': '868201803000695'}, {'cow_number': '868201803000688'}, {'cow_number': '868201803000681'}, {'cow_number': '868201803000703'}, {'cow_number': '868201803000674'}, {'cow_number': '868201803000651'}, {'cow_number': '180078'}, {'cow_number': '180025'}, {'cow_number': '130558'}, {'cow_number': '160080'}, {'cow_number': '160090'}, {'cow_number': '170071'}, {'cow_number': '170087'}, {'cow_number': '170099'}, {'cow_number': '170135'}, {'cow_number': '150153'}, {'cow_number': '160073'}, {'cow_number': '170083'}, {'cow_number': '150037'}, {'cow_number': '150249'}, {'cow_number': '160168'}, {'cow_number': '160002'}, {'cow_number': '170080'}, {'cow_number': '140157'}, {'cow_number': '160225'}, {'cow_number': '140161'}, {'cow_number': '140588'}, {'cow_number': '160804'}, {'cow_number': '140170'}, {'cow_number': '160068'}, {'cow_number': '16411'}, {'cow_number': '160527'}, {'cow_number': '180070'}, {'cow_number': '180026'}, {'cow_number': '180034'}, {'cow_number': '180004'}, {'cow_number': '1003'}, {'cow_number': '130653'}, {'cow_number': '160170'}, {'cow_number': '180753'}, {'cow_number': '180795'}, {'cow_number': '180698'}, {'cow_number': '180675'}, {'cow_number': '20191001'}, {'cow_number': '20191002'}, {'cow_number': '140680'}, {'cow_number': '170058'}, {'cow_number': '170159'}, {'cow_number': '160059'}, {'cow_number': '170095'}, {'cow_number': '150092'}, {'cow_number': '20200221'}, {'cow_number': '20200224'}, {'cow_number': '20200226'}, {'cow_number': '130739'}, {'cow_number': '160169'}, {'cow_number': '150641'}, {'cow_number': '160829'}, {'cow_number': '20200301'}, {'cow_number': '2020030111'}, {'cow_number': '202003011112'}, {'cow_number': '170151'}, {'cow_number': '150350'}, {'cow_number': '180007'}, {'cow_number': '110615'}, {'cow_number': '160250'}, {'cow_number': '170107'}, {'cow_number': '150039'}, {'cow_number': '170153'}, {'cow_number': '110926'}, {'cow_number': '170136'}, {'cow_number': '160097'}, {'cow_number': '160423'}, {'cow_number': '160329'}, {'cow_number': '170069'}, {'cow_number': '170152'}, {'cow_number': '140738'}, {'cow_number': '110301'}, {'cow_number': '170092'}, {'cow_number': '160098'}, {'cow_number': '150090'}, {'cow_number': '180748'}]
    [{'cow_number': '1002'}, {'cow_number': '1005'}, {'cow_number': '2007'}, {'cow_number': '3001'}, {'cow_number': '3004'}, {'cow_number': '868201803000700'}, {'cow_number': '868201803000704'}, {'cow_number': '868201803000702'}, {'cow_number': '868201803000696'}, {'cow_number': '868201803000701'}, {'cow_number': '868201803000697'}, {'cow_number': '868201803000699'}, {'cow_number': '868201803000689'}, {'cow_number': '868201803000682'}, {'cow_number': '868201803000695'}, {'cow_number': '868201803000688'}, {'cow_number': '868201803000681'}, {'cow_number': '868201803000703'}, {'cow_number': '868201803000674'}, {'cow_number': '868201803000651'}, {'cow_number': '180078'}, {'cow_number': '180025'}, {'cow_number': '130558'}, {'cow_number': '160080'}, {'cow_number': '160090'}, {'cow_number': '170071'}, {'cow_number': '170087'}, {'cow_number': '170099'}, {'cow_number': '170135'}, {'cow_number': '150153'}, {'cow_number': '160073'}, {'cow_number': '170083'}, {'cow_number': '150037'}, {'cow_number': '150249'}, {'cow_number': '160168'}, {'cow_number': '160002'}, {'cow_number': '170080'}, {'cow_number': '140157'}, {'cow_number': '160225'}, {'cow_number': '140161'}, {'cow_number': '140588'}, {'cow_number': '160804'}, {'cow_number': '140170'}, {'cow_number': '160068'}, {'cow_number': '16411'}, {'cow_number': '160527'}, {'cow_number': '180070'}, {'cow_number': '180026'}, {'cow_number': '180034'}, {'cow_number': '180004'}, {'cow_number': '1003'}, {'cow_number': '130653'}, {'cow_number': '160170'}, {'cow_number': '180753'}, {'cow_number': '180795'}, {'cow_number': '180698'}, {'cow_number': '180675'}, {'cow_number': '20191001'}, {'cow_number': '20191002'}, {'cow_number': '140680'}, {'cow_number': '170058'}, {'cow_number': '170159'}, {'cow_number': '160059'}, {'cow_number': '170095'}, {'cow_number': '150092'}, {'cow_number': '20200221'}, {'cow_number': '20200224'}, {'cow_number': '20200226'}, {'cow_number': '130739'}, {'cow_number': '160169'}, {'cow_number': '150641'}, {'cow_number': '160829'}, {'cow_number': '20200301'}, {'cow_number': '2020030111'}, {'cow_number': '202003011112'}, {'cow_number': '170151'}, {'cow_number': '150350'}, {'cow_number': '180007'}, {'cow_number': '110615'}, {'cow_number': '160250'}, {'cow_number': '170107'}, {'cow_number': '150039'}, {'cow_number': '170153'}, {'cow_number': '110926'}, {'cow_number': '170136'}, {'cow_number': '160097'}, {'cow_number': '160423'}, {'cow_number': '160329'}, {'cow_number': '170069'}, {'cow_number': '170152'}, {'cow_number': '140738'}, {'cow_number': '110301'}, {'cow_number': '170092'}, {'cow_number': '160098'}, {'cow_number': '150090'}, {'cow_number': '180748'}]
    [{'cow_number': '1002'}, {'cow_number': '1005'}, {'cow_number': '2007'}, {'cow_number': '3001'}, {'cow_number': '3004'}, {'cow_number': '868201803000700'}, {'cow_number': '868201803000704'}, {'cow_number': '868201803000702'}, {'cow_number': '868201803000696'}, {'cow_number': '868201803000701'}, {'cow_number': '868201803000697'}, {'cow_number': '868201803000699'}, {'cow_number': '868201803000689'}, {'cow_number': '868201803000682'}, {'cow_number': '868201803000695'}, {'cow_number': '868201803000688'}, {'cow_number': '868201803000681'}, {'cow_number': '868201803000703'}, {'cow_number': '868201803000674'}, {'cow_number': '868201803000651'}, {'cow_number': '180078'}, {'cow_number': '180025'}, {'cow_number': '130558'}, {'cow_number': '160080'}, {'cow_number': '160090'}, {'cow_number': '170071'}, {'cow_number': '170087'}, {'cow_number': '170099'}, {'cow_number': '170135'}, {'cow_number': '150153'}, {'cow_number': '160073'}, {'cow_number': '170083'}, {'cow_number': '150037'}, {'cow_number': '150249'}, {'cow_number': '160168'}, {'cow_number': '160002'}, {'cow_number': '170080'}, {'cow_number': '140157'}, {'cow_number': '160225'}, {'cow_number': '140161'}, {'cow_number': '140588'}, {'cow_number': '160804'}, {'cow_number': '140170'}, {'cow_number': '160068'}, {'cow_number': '16411'}, {'cow_number': '160527'}, {'cow_number': '180070'}, {'cow_number': '180026'}, {'cow_number': '180034'}, {'cow_number': '180004'}, {'cow_number': '1003'}, {'cow_number': '130653'}, {'cow_number': '160170'}, {'cow_number': '180753'}, {'cow_number': '180795'}, {'cow_number': '180698'}, {'cow_number': '180675'}, {'cow_number': '20191001'}, {'cow_number': '20191002'}, {'cow_number': '140680'}, {'cow_number': '170058'}, {'cow_number': '170159'}, {'cow_number': '160059'}, {'cow_number': '170095'}, {'cow_number': '150092'}, {'cow_number': '20200221'}, {'cow_number': '20200224'}, {'cow_number': '20200226'}, {'cow_number': '130739'}, {'cow_number': '160169'}, {'cow_number': '150641'}, {'cow_number': '160829'}, {'cow_number': '20200301'}, {'cow_number': '2020030111'}, {'cow_number': '202003011112'}, {'cow_number': '170151'}, {'cow_number': '150350'}, {'cow_number': '180007'}, {'cow_number': '110615'}, {'cow_number': '160250'}, {'cow_number': '170107'}, {'cow_number': '150039'}, {'cow_number': '170153'}, {'cow_number': '110926'}, {'cow_number': '170136'}, {'cow_number': '160097'}, {'cow_number': '160423'}, {'cow_number': '160329'}, {'cow_number': '170069'}, {'cow_number': '170152'}, {'cow_number': '140738'}, {'cow_number': '110301'}, {'cow_number': '170092'}, {'cow_number': '160098'}, {'cow_number': '150090'}, {'cow_number': '180748'}]
    Exception in thread Thread-9:
    Traceback (most recent call last):
      File "E:pythonlib	hreading.py", line 926, in _bootstrap_inner
        self.run()
      File "E:pythonlib	hreading.py", line 870, in run
        self._target(*self._args, **self._kwargs)
      File "F:/pycharm测试功能文件夹/single_pool/test_code.py", line 10, in test
        single_instance.get_all()
      File "F:pycharm测试功能文件夹single_pool	est_mysqlmysql_pool_test.py", line 47, in get_all
        cursor.execute(sql)
      File "E:pythonlibsite-packagesDBUtilsSteadyDB.py", line 605, in tough_method
        result = method(*args, **kwargs)  # try to execute
      File "E:pythonlibsite-packagespymysqlcursors.py", line 170, in execute
        result = self._query(query)
      File "E:pythonlibsite-packagespymysqlcursors.py", line 328, in _query
        conn.query(q)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 517, in query
        self._affected_rows = self._read_query_result(unbuffered=unbuffered)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 732, in _read_query_result
        result.read()
      File "E:pythonlibsite-packagespymysqlconnections.py", line 1082, in read
        self._read_result_packet(first_packet)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 1152, in _read_result_packet
        self._read_rowdata_packet()
      File "E:pythonlibsite-packagespymysqlconnections.py", line 1186, in _read_rowdata_packet
        packet = self.connection._read_packet()
      File "E:pythonlibsite-packagespymysqlconnections.py", line 657, in _read_packet
        packet_header = self._read_bytes(4)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 691, in _read_bytes
        data = self._rfile.read(num_bytes)
    AttributeError: 'NoneType' object has no attribute 'read'
    
    Exception in thread Thread-5:
    Traceback (most recent call last):
      File "E:pythonlib	hreading.py", line 926, in _bootstrap_inner
        self.run()
      File "E:pythonlib	hreading.py", line 870, in run
        self._target(*self._args, **self._kwargs)
      File "F:/pycharm测试功能文件夹/single_pool/test_code.py", line 10, in test
        single_instance.get_all()
      File "F:pycharm测试功能文件夹single_pool	est_mysqlmysql_pool_test.py", line 47, in get_all
        cursor.execute(sql)
      File "E:pythonlibsite-packagesDBUtilsSteadyDB.py", line 605, in tough_method
        result = method(*args, **kwargs)  # try to execute
      File "E:pythonlibsite-packagespymysqlcursors.py", line 170, in execute
        result = self._query(query)
      File "E:pythonlibsite-packagespymysqlcursors.py", line 328, in _query
        conn.query(q)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 516, in query
        self._execute_command(COMMAND.COM_QUERY, sql)
      File "E:pythonlibsite-packagespymysqlconnections.py", line 750, in _execute_command
        raise err.InterfaceError("(0, '')")
    pymysql.err.InterfaceError: (0, '')
    
    [{'cow_number': '1002'}, {'cow_number': '1005'}, {'cow_number': '2007'}, {'cow_number': '3001'}, {'cow_number': '3004'}, {'cow_number': '868201803000700'}, {'cow_number': '868201803000704'}, {'cow_number': '868201803000702'}, {'cow_number': '868201803000696'}, {'cow_number': '868201803000701'}, {'cow_number': '868201803000697'}, {'cow_number': '868201803000699'}, {'cow_number': '868201803000689'}, {'cow_number': '868201803000682'}, {'cow_number': '868201803000695'}, {'cow_number': '868201803000688'}, {'cow_number': '868201803000681'}, {'cow_number': '868201803000703'}, {'cow_number': '868201803000674'}, {'cow_number': '868201803000651'}, {'cow_number': '180078'}, {'cow_number': '180025'}, {'cow_number': '130558'}, {'cow_number': '160080'}, {'cow_number': '160090'}, {'cow_number': '170071'}, {'cow_number': '170087'}, {'cow_number': '170099'}, {'cow_number': '170135'}, {'cow_number': '150153'}, {'cow_number': '160073'}, {'cow_number': '170083'}, {'cow_number': '150037'}, {'cow_number': '150249'}, {'cow_number': '160168'}, {'cow_number': '160002'}, {'cow_number': '170080'}, {'cow_number': '140157'}, {'cow_number': '160225'}, {'cow_number': '140161'}, {'cow_number': '140588'}, {'cow_number': '160804'}, {'cow_number': '140170'}, {'cow_number': '160068'}, {'cow_number': '16411'}, {'cow_number': '160527'}, {'cow_number': '180070'}, {'cow_number': '180026'}, {'cow_number': '180034'}, {'cow_number': '180004'}, {'cow_number': '1003'}, {'cow_number': '130653'}, {'cow_number': '160170'}, {'cow_number': '180753'}, {'cow_number': '180795'}, {'cow_number': '180698'}, {'cow_number': '180675'}, {'cow_number': '20191001'}, {'cow_number': '20191002'}, {'cow_number': '140680'}, {'cow_number': '170058'}, {'cow_number': '170159'}, {'cow_number': '160059'}, {'cow_number': '170095'}, {'cow_number': '150092'}, {'cow_number': '20200221'}, {'cow_number': '20200224'}, {'cow_number': '20200226'}, {'cow_number': '130739'}, {'cow_number': '160169'}, {'cow_number': '150641'}, {'cow_number': '160829'}, {'cow_number': '20200301'}, {'cow_number': '2020030111'}, {'cow_number': '202003011112'}, {'cow_number': '170151'}, {'cow_number': '150350'}, {'cow_number': '180007'}, {'cow_number': '110615'}, {'cow_number': '160250'}, {'cow_number': '170107'}, {'cow_number': '150039'}, {'cow_number': '170153'}, {'cow_number': '110926'}, {'cow_number': '170136'}, {'cow_number': '160097'}, {'cow_number': '160423'}, {'cow_number': '160329'}, {'cow_number': '170069'}, {'cow_number': '170152'}, {'cow_number': '140738'}, {'cow_number': '110301'}, {'cow_number': '170092'}, {'cow_number': '160098'}, {'cow_number': '150090'}, {'cow_number': '180748'}]
    
    Process finished with exit code 0

    # TODO

    # 池中空闲连接的初始数目,0表示
  • 相关阅读:
    OO第四单元单元总结
    OO第三单元单元总结
    OO第二单元单元总结
    OO第一单元单元总结
    Java虚拟机解释器与编译器
    20155321 《Java程序设计》实验三 敏捷开发与XP实践
    20155321 2016-2017-2 《Java程序设计》第十周学习总结
    20155321 2016-2017-2 《Java程序设计》第九周学习总结
    20155321实验二 Java面向对象程序设计
    20155321 2016-2017-2 《Java程序设计》第八周学习总结
  • 原文地址:https://www.cnblogs.com/meloncodezhang/p/12567738.html
Copyright © 2020-2023  润新知