sqlalchemy: stopping a long-running query

397 views
Skip to first unread message

Cody Django

unread,
Feb 24, 2012, 3:47:17 PM2/24/12
to sqlalchemy
Hi guys -- hopefully this is an easy answer for someone! I've also
posted the problem to stack overflow:
http://stackoverflow.com/questions/9437498/sqlalchemy-stopping-a-long-running-query


I'm using sqlalchemy to query postgres. If a client timeout occurs,
I'd like to stop/cancel the long running postgres queries from another
thread. The thread has access to the Session or Connection object.

At this point I've tried:

session.bind.raw_connection().close()
and
session.connection().close()
and
session.close
and
session.transaction.close()

But no matter what I try, the postgres query still continues until
it's end. I know this from watching pg in top. Shouldn't this be
fairly easy to do? I'm I missing something? Is this impossible without
getting the pid and sending a stop signal directly?

Thanks so much,

Cody

Michael Bayer

unread,
Feb 24, 2012, 4:06:53 PM2/24/12
to sqlal...@googlegroups.com
I'd augment the comments on the SO post by saying you'd want to look at psycopg2 directly, and possibly ask on their mailing list, what the expected behavior and options are here. If you provide sample code to the psycopg2 folks, make sure that code is in terms of psycopg2 directly and not any SQLAlchemy, lest they dismiss your issue as something specific to SQLAlchemy.

> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>

Cody Django

unread,
Feb 24, 2012, 8:10:08 PM2/24/12
to sqlalchemy
Heh, thanks Michael!

I believe to have found a working solution, using a special "cancel"
method that was introduced in the 2.4 psycopg2 driver. I've updated
the SO post with my current solution.

Thanks for the quick reply!

Cody


On Feb 24, 1:06 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> I'd augment the comments on the SO post by saying you'd want to look at psycopg2 directly, and possibly ask on their mailing list, what the expected behavior and options are here.  If you provide sample code to the psycopg2 folks, make sure that code is in terms of psycopg2 directly and not any SQLAlchemy, lest they dismiss your issue as something specific to SQLAlchemy.
>
> On Feb 24, 2012, at 3:47 PM, Cody Django wrote:
>
>
>
>
>
>
>
> > Hi guys -- hopefully this is an easy answer for someone!  I've also
> > posted the problem to stack overflow:
> >http://stackoverflow.com/questions/9437498/sqlalchemy-stopping-a-long...
Reply all
Reply to author
Forward
0 new messages