Am 21.06.2010 um 19:13 schrieb yoav glazner:
On Mon, Jun 21, 2010 at 2:48 PM, Gaetan de Menten
<[email protected]> wrote:
On Sun, Jun 20, 2010 at 15:10, yoav glazner <[email protected]>
wrote:
> Hi,
> I have a problem in my program, i can replacte it this way:
> <code>
> from elixir import *
> class Job(Entity):
> number = Field(Integer)
> def f(job):
> job.expire()
> job.number
> metadata.bind = "oracle://user:passw...@db"
> setup_all()
> job = Job.query.get(1) #number is primary key
> thread.start_new(f,(job,))
> thread.start_new(f,(job,))
> time.sleep(4)
> </code>
> ok now i get this:
> AttributeError: expired_attributes
> how should i approch this?
> (I know that if i put a lock on function "f" it doesn't happen...)
As far as I know, you shouldn't share a particular object instance
between several threads.
The answer to the question: "Is the session thread-safe?" in:
http://www.sqlalchemy.org/docs/session.html#frequently-asked-questions
applies to your case. But you can perfectly load the same row in two
different threads...
If one thread can only read then this should be safe?
def f(jobNumber):
job = Job.get(jobNumber)
job.expire()
job.number
(f is a threaded function ...)
I can't test this now since i don't have a DB here =(
Looks good, yes.
Diez
--
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.