On 10/24/07, Simon Cross <[EMAIL PROTECTED]> wrote:
>
> I'm attempting to get Elixir (trunk) with SQLAlchemy 0.4 running
> inside a multi-threaded environment (CherryPy) without much luck. I
> read the previous list postings I could find but none of the solutions
> offered seem to help (or I am misunderstanding the advice). I've
> create a small test script which highlights the problem I'm
> experiencing:

What breaks your example has nothing to do with Elixir. It left me
puzzled for a bit, but it seems like an in-memory sqlite database
can't be shared between several threads, hence the error (in the
second thread, the table doesn't exist). Try using a file, or another
DB.

Other than that, you don't need to bind both the sesion and the
metadata. It's usually one or the other. And I suggest you use an
explicit setup_all() call (see the upgrade notes on the Wiki), because
even if your code works here (after resolving the sqlite problem), you
might run into strange problems if the setup is triggered at a bad
time (for example in two different threads at the same time).

Hope this helps,

> """START OF ThreadTest.py"""
>
> from elixir import *
> from sqlalchemy.orm import sessionmaker, scoped_session
> from sqlalchemy.ext.sessioncontext import SessionContext
> import sqlalchemy
>
> __metadata__ = sqlalchemy.MetaData()
> __session__ = scoped_session(sessionmaker(autoflush=True))
>
> class Pet(Entity):
>     has_field('name', Unicode(30))
>     using_options(tablename='pet')
>
> def bind(engine):
>     global __metadata__, __session__
>     __metadata__.bind = engine
>     __session__.configure(bind=engine)
>
> def init():
>     create_all()
>     felix = Pet(name='Felix')
>     __session__.flush()
>
> if __name__ == "__main__":
>     import threading
>     import time
>
>     engine = sqlalchemy.create_engine("sqlite:///:memory:")
>     bind(engine)
>
>     t = threading.Thread(target=init)
>     t.start()
>     t.join()
>
>     Pet.query().all()
>
> """END OF ThreadTest.py"""
>
> Running "python ThreadTest.py" throws:
>
> sqlalchemy.exceptions.OperationalError: (OperationalError) no such
> table: pet u'SELECT pet.id AS pet_id, pet.name AS pet_name \nFROM pet
> ORDER BY pet.oid' []
>
> Any pointers on what I'm doing wrong would be appreciated.
>
> Schiavo
> Simon
>
>
> >
>


-- 
Gaƫtan de Menten
http://openhex.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to