- changed status to invalid
Dynamic Metadata connected in one thread isn't in another.
Issue #629
resolved
I'm not sure this is a bug, or a wrong usage. I couldn't find any documentation/wiki entry on this.
Unhandled exception in thread started by <function do_something at 0xb7964f7c>
Traceback (most recent call last):
File "test.py", line 16, in do_something
print cover.select().execute()
File "build/bdist.linux-i686/egg/sqlalchemy/sql.py", line 1175, in execute
File "build/bdist.linux-i686/egg/sqlalchemy/sql.py", line 1063, in execute
sqlalchemy.exceptions.InvalidRequestError: This Compiled object is not bound to any engine.
#!python
import thread, time
from sqlalchemy import create_engine, BoundMetaData, DynamicMetaData, Sequence, Integer, String, Table, Column
engine = create_engine('mysql://mysql:mysql@copperhead/web_shop_development')
meta = DynamicMetaData()
meta.connect(engine)
# meta = BoundMetaData(engine) #this succeeds, is it thread-safe?
cover = Table('cover', meta,
Column('cover_id', Integer, Sequence('cover_seq'), primary_key=True),
Column('name', String(128), nullable=False),
)
def do_something():
print cover.select().execute()
thread.start_new_thread(do_something, ())
time.sleep(3)
Comments (1)
-
repo owner - Log in to comment
from the docs:
Another form of MetaData exits which can connect to an engine within the current thread (or "on a per-thread basis"), allowing other threads to be connected to different engines simultaneously: (example) DynamicMetaData is intended for applications that need to use the same set of Tables for many different database connections in the same process, such as a CherryPy web application which handles multiple application instances in one process.
use MetaData if you dont want thread-local.