Comments (8)
@modaye 请提供可以重现的简单代码,谢谢
from taos-connector-python.
@modaye请提供可以返回的简单代码,谢谢
hellozai/db/base.py
import logging
import functools
import textwrap
from typing import Optional, Callable
from collections import ChainMap
import taos
logger = logging.getLogger(__name__)
def create_taos_connect(
host: str = "localhost",
port: int = 6030,
user: str = "root",
password: str = "taosdata",
database: Optional[str] = None,
**kwargs
) -> taos.TaosConnection:
params = {
"host": host,
"port": port,
"user": user,
"password": password,
"database": database
}
params = {k: v for k, v in params.items() if v is not None}
kwargs.update(params)
config = ChainMap(kwargs)
# 将taos连接器进行包装 对调用进行捕获或拦截
_db_conn = ConnectWrapper(taos.connect(**config))
logger.info(
f"taos connect host:%s port: %s database: %s",
config.get('host'), config.get('port'), config.get('database')
)
return _db_conn # type: ignore
def params_catch(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if args:
logger.debug("func: %s, args: %s", func.__name__, textwrap.shorten(args[0], width=300, placeholder="..."))
return func(*args, **kwargs)
return wrapper
class ConnectWrapper:
def __init__(self, conn: taos.TaosConnection):
self._conn = conn
def __getattr__(self, item):
attr = getattr(self._conn, item)
if isinstance(attr, Callable):
return params_catch(attr)
return attr
在base.py 中直接获取连接对象执行任意数据库操作不会报错,但是当在其他模块引用该 create_taos_connect 函数并建立连接就产生上面的报错。
run.py
from hellozai.db import create_taos_connect
db = create_taos_connect()
db.execute("show databases;")
引用相同的 base.py 代码在3个不同的电脑(Ubuntu 20.04)均稳定复现错误。
from taos-connector-python.
我在多个版本下下均未复现。只能建议检查下环境。
from taos-connector-python.
我在 windows 上 用多个版本 python 测试,也均无复现。 最好提供项目结构的细节。
from taos-connector-python.
确实是特定的项目才会复现该问题, 我在hellozai 目录下还有一个models
包, 包中的models.py
文件中 也导入了taos
用于其中函数的类型注解,经过测试只要在该 models.py
模块中导入 taos
就引发错误。
已经放弃在该模块添加类型提示,使用 models.pyi
作为注解存根不会引发错误
在其他命名的项目下,复制 hellozai
内部所有文件,进行测试也不会产生错误
from taos-connector-python.
这是一个奇怪的问题,将代码copy 到其他由Pycharm 创建的项目下,并不会引发报错。
from taos-connector-python.
我在多个版本下下均未复现。只能建议检查下环境。
感谢
from taos-connector-python.
我在 windows 上 用多个版本 python 测试,也均无复现。 最好提供项目结构的细节。
感谢
from taos-connector-python.
Related Issues (20)
- SQLAlchemy support is not completed HOT 4
- Will the connector support python asyncio? HOT 2
- when using a dnode, conn throws an exception HOT 5
- test and examples should not be included HOT 2
- Importing pandas dataframe on TDengine. HOT 1
- 流函数支持 HOT 2
- taos_fetch_block _v3 is slow HOT 4
- python库query结果非utc时间,造成数据有8小时误差 HOT 3
- Crash when importing pyarrow after taos imported HOT 1
- taospy 获取 tdengine的查询数据的速度异常 HOT 5
- taos-ws-py 查询结果循环输出报错 HOT 5
- interp function executing failed by taospy HOT 1
- 源码中这部分逻辑跳过了
- window下漏查数据 HOT 1
- bind params error HOT 3
- export to csv file error HOT 1
- 增加api进行时间戳转换控制
- pd.read_sql get timestamp when the db time precision is ns HOT 2
- AttributeError: /lib/libtaos.so: undefined symbol: taos_subscribe HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taos-connector-python.