is it true of sqlalchemy verison 0.7 (which BTW I am using)?

If I close() explicitly only for insert queries, I can see that parallel 
inserts happening equal to no. of threads that I have, but if I remove it, 
no parallel inserts happen(I am checking this by using show processlist on 
mysql prompt)

pool_size = 150 : when close() is called.
pool_size = 30 : when close() in not called.

I had to bump the pool_size as log of 'wait timeout exceeded' errors were 
seen in the application log.  

I am taking care of creating new session per thread which is not being 
shared with others.


BTW fetch_all( ) from result worked in case select queries, but we are 
still experimenting to eliminate / minimize the other errors
  

On Monday, September 22, 2014 11:14:04 AM UTC-5, Milind Vaidya wrote:
>
> HI 
>
> I have following code,
>
>
>
>
>     @db_error_handler
>     def execute_query(self, query_str, data=None):
>         '''Execute DB query and retry for common DB interaction errors'''
>         errors_concerned = [1213, 1205, 2013, 2006]
>         attempts = 1 
>         while(True):
>             try:
>                 result = self.session.execute(query_str, data)
>                 #result.close() : Trying to commonize insert/select
>                 self.session.commit()
>                 return result
>             except OperationalError as oe: 
>                 self.session.rollback()
>                 if oe.orig[0] in errors_concerned:
>                     if attempts <= 3:
>                         logger.error("Error occured in attempts %s: %s" % 
> (attempts, oe.orig))
>                         time.sleep(2 * attempts)
>                     attempts += 1
>                         continue
>                     else:
>                         logger.error("Error occured, attempts exhausted 
> %s: %s" % (attempts, oe.orig))
>             break
>                 else:
>             raise
>
>
> I am constructing the queries outside and passing to this function. I want 
> to return result in case of select queries. But I can not do that if I call 
> result.close() before returning. Without closing the result, insert queries 
> have a problem.
>
> ERROR: DB operation failure: (ProgrammingError) (2014, "Commands out of 
> sync; you can't run this command now") None None
>
>
> So I was thinking of using 
>
> is_insert¶ 
> <http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.ResultProxy.is_insert>
>
> True if this ResultProxy 
> <http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.ResultProxy>
>  
> is the result of a executing an expression language compiled 
> expression.insert() 
> <http://docs.sqlalchemy.org/en/rel_0_7/core/expression_api.html#sqlalchemy.sql.expression.insert>
>  
> construct.
>
> When True, this implies that the inserted_primary_key 
> <http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.ResultProxy.inserted_primary_key>
>  
> attribute is accessible, assuming the statement did not include a user 
> defined “returning” construct.
>
> to check if the query resulted in insert and then call close skip 
> otherwise ? Is it ok from semantic point of view ? Also will it result it 
> inconsistent connection state or connections ?
>

-- 
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.

Reply via email to