Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.066 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'table.': 0.07; 'postgresql,': 0.09; 'second.': 0.09; 'whatever.': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'thread': 0.14; 'blocking': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'timestamps': 0.16; 'wrote:': 0.18; 'backend': 0.19; 'server,': 0.19; 'select': 0.22; 'minutes.': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'script': 0.25; 'query': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'larry': 0.31; 'probably': 0.32; 'run': 0.32; 'quite': 0.32; 'fri,': 0.33; 'table': 0.34; 'info': 0.35; 'connection': 0.35; 'transaction': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'idle': 0.36; 'oracle': 0.36; 'doing': 0.36; 'should': 0.36; 'too': 0.37; 'sometimes': 0.38; 'rather': 0.38; 'that,': 0.38; 'anything': 0.39; 'does': 0.39; 'delete': 0.39; 'skip:- 60': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'even': 0.60; 'monitoring': 0.61; "you're": 0.61; "you'll": 0.62; 'such': 0.63; 'more': 0.64; 'taking': 0.65; 'facilities': 0.69; 'jul': 0.74; '(better': 0.84; 'started,': 0.84; 'transactions': 0.91; 'whereas': 0.91; 'to:none': 0.92; 'connection,': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=PNYUxUGtm14BY/XrFBLX45q74LKtphVSpn6ueXgtd7c=; b=DxphePDk13JJqVeLsuQ+q2I0HWOIsB0zRRdsLXZwoldMmvbsv86MQ6NaRBg2B6pxbR 9mJJX4KUYOk4DswFBdrNivel7sWQxCYbtYMjMVwDQpooZA61d/aEEdUNgTRUZylm0iT/ dKl8onLX8+YmuZWBoxb44PR22zQ1oJFKoPK6MJc/BB7/h9NIx4zWeRU/dNqgX0KUl1j5 WJrKc3Y0GO8siBuBG+T6EuIAihtTi7ufBiy0XxiDCyIjGR1TsN2eYTZIyQx5NmQtreDV jns1TrqcEwzFkNZPA5iVFKknvACXSYOG6meAnImHD/XWNikzvNi3F8ItUCxUq8SaBGBP uPFw== MIME-Version: 1.0 X-Received: by 10.220.81.194 with SMTP id y2mr27170681vck.29.1405618328624; Thu, 17 Jul 2014 10:32:08 -0700 (PDT) In-Reply-To: References: Date: Fri, 18 Jul 2014 03:32:08 +1000 Subject: Re: Blocked thread From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405618331 news.xs4all.nl 2872 [2001:888:2000:d::a6]:36757 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74651 On Fri, Jul 18, 2014 at 2:26 AM, Larry Martell wrote: > I have a python cx_Oracle script that does a delete from a table. > Usually this takes well under 1 second. But sometimes it takes 1 to 2 > minutes. I wanted to monitor that delete and if it's taking too long I > want to see what is blocking it. I run the delete sql in a thread... I don't know Oracle specifically, but if it's anything like PostgreSQL, you'll probably do better with a completely separate connection to the server, which might need to be a separate process. In PostgreSQL, I can query currently-active transactions thus: rosuav=> select state,query from pg_stat_activity; state | query ---------------------+------------------------------------------- idle in transaction | select * from pg_stat_activity; active | select state,query from pg_stat_activity; active | drop table test; (3 rows) (Better than that: Add "where pid=..." to that, using the backend PID provided by the thread you're monitoring, by "SELECT pg_backend_pid()". But that's even more PostgreSQL-specific.) With info like that, you can see what's happening, and whether it's stalled out or in a query or whatever. You should also be able to get some timestamps (Postgres can do that, I would be highly surprised if Oracle can't), such as when the transaction started, so you can see how long it's been stalled. Thing is, this requires a quite separate connection, which means you're monitoring the far end rather than the local thread. I suspect this will give you better results; Oracle's bound to have facilities for doing this, whereas your local thread may or may not be usefully monitorable. ChrisA