diff --git a/pydbapi/api/mysql.py b/pydbapi/api/mysql.py index cee353f..8a0eebc 100644 --- a/pydbapi/api/mysql.py +++ b/pydbapi/api/mysql.py @@ -1,7 +1,7 @@ # @Author: chunyang.xu # @Email: 398745129@qq.com # @Date: 2020-06-10 14:40:50 -# @Last Modified time: 2021-11-16 18:42:55 +# @Last Modified time: 2021-11-20 10:22:21 # @github: https://github.com/longfengpili # !/usr/bin/env python3 @@ -114,7 +114,9 @@ def __init__(self, host, user, password, database, port=3306, charset="utf8", sa def __new__(cls, *args, **kwargs): if not hasattr(MysqlDB, '_instance'): + mysqllogger.info(MysqlDB._instance_lock) with MysqlDB._instance_lock: + mysqllogger.info(MysqlDB._instance_lock) if not hasattr(MysqlDB, '_instance'): MysqlDB._instance = super().__new__(cls) @@ -122,10 +124,12 @@ def __new__(cls, *args, **kwargs): @classmethod def get_instance(cls, *args, **kwargs): + mysqllogger.info('1') if not hasattr(MysqlDB, '_instance'): + mysqllogger.info(MysqlDB._instance_lock) with MysqlDB._instance_lock: if not hasattr(MysqlDB, '_instance'): - MysqlDB._instance = MysqlDB(*args, **kwargs) + MysqlDB._instance = super().__new__(cls) return MysqlDB._instance diff --git a/setup.py b/setup.py index a800eb3..bf36aaa 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # @Author: chunyang.xu # @Email: 398745129@qq.com # @Date: 2020-06-09 16:46:54 -# @Last Modified time: 2021-11-19 14:57:01 +# @Last Modified time: 2021-11-20 10:22:31 # @github: https://github.com/longfengpili # !/usr/bin/env python3 @@ -12,7 +12,7 @@ import shutil import setuptools -VERSION = '0.0.78' +VERSION = '0.0.79' PROJECT_NAME = 'pydbapi' with open('README.md', 'r', encoding='utf-8') as f: diff --git a/tests/mysql/mysql_test.py b/tests/mysql/mysql_test.py index 847ab8c..41d6a17 100644 --- a/tests/mysql/mysql_test.py +++ b/tests/mysql/mysql_test.py @@ -2,7 +2,7 @@ # @Author: chunyang.xu # @Date: 2021-03-08 14:19:01 # @Last Modified by: chunyang.xu -# @Last Modified time: 2021-11-16 18:41:11 +# @Last Modified time: 2021-11-20 10:15:24 import os import pytest @@ -35,13 +35,13 @@ def teardown_method(self, method): def test_get_instance(self): mysql1 = MysqlDB.get_instance(safe_rule=False, **self.AdLocal) - mysql2 = MysqlDB.get_instance(safe_rule=False, **self.AdLocal) - mysql3 = MysqlDB(safe_rule=False, **self.AdLocal) - mysql4 = MysqlDB(safe_rule=False, **self.AdLocal) - print(mysql1, mysql2, mysql3, mysql4) - for i in dir(mysql4): - result = eval(f"mysql4.{i}") - print(f"【{i}】: {result}") + # mysql2 = MysqlDB.get_instance(safe_rule=False, **self.AdLocal) + # mysql3 = MysqlDB(safe_rule=False, **self.AdLocal) + # mysql4 = MysqlDB(safe_rule=False, **self.AdLocal) + # print(mysql1, mysql2, mysql3, mysql4) + # for i in dir(mysql4): + # result = eval(f"mysql4.{i}") + # print(f"【{i}】: {result}") def test_drop(self): rows, action, result = self.mysqldb.drop(self.tablename)