Sorry, see "attached test script" here: from sqlalchemy import * import logging import threading import time import os
logging.basicConfig(level = logging.INFO, format = '%(levelname)s:%(asctime)s:%(thread)d:%(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('mytable', metadata, autoload=True, autoload_with=engine) logging.info("size of columns:[%s]", len(table.columns)) except: logging.warn("error occured", exc_info = True) logging.info("starting") for i in range(5): t = threading.Thread(target = load_table) t.daemon = False t.start() time.sleep(2) os._exit(0) On Sunday, October 25, 2015 at 3:37:55 PM UTC+8, peon ma wrote: > > Hello > > I have a problem with table reflection under multi-thread without lock. > It works fine under single-thread or multi thread with lock protection. > > I got following result by the attached test script: > single-thread or multi thread with lock protection: > It prints some logs of create connection, query metadata etc, and then > the table reflection returned. > multi-thread without lock protection: > table reflection returned before create connection and query metadata, > without any exceptions, loggings, but got empty columns list > and after about 20ms(metadata of this table fetched), all threads > works fine(got correct columns list) > > > I did found any related documentation about this, so I want to know: > Is it a bug? > Or the reflection isn't thread-safe, if so, is it thread-safe for > reflection different tables?(see following code for example) > with tbl1_lock: > Table("table1", ... ) > > with tbl2_lock: > Table("table2", ...) > > > Thanks in advance > > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.