自动加载线程安全吗?我找不到任何关于此的文件。 通过以下代码,在大约前20ms内无法成功加载表(没有异常,没有警告或更高的日志,但table.columns是一个空列表),然后正常工作
from sqlalchemy import *
import logging
import threading
import time
logging.basicConfig(level = logging.INFO, format = '%(asctime)s:%(message)s', filename = "autoload_test.log")
logging.getLogger("sqlalchemy").setLevel(logging.DEBUG)
engine = create_engine("postgresql://madk@localhost/mydb", echo = False)
metadata = MetaData(bind=engine)
lock = threading.Lock()
def load_table():
while True:
try:
table = Table('mytbl', metadata, autoload=True, autoload_with=engine)
logging.info("size of columns:[%s]", len(table.columns))
except:
logging.warn("error occured", exc_info = True)
for i in range(5):
t = threading.Thread(target = load_table)
t.daemon = False
t.start()
time.sleep(4)