473,511 Members | 14,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dumping the state of a deadlocked process

Hi all

I'm currently having some issues with a process getting deadlocked. The
problem is that the only way I can seem to find information about where
it deadlocks is by making a wild guess, insert a pdb.set_trace() before
this point, and then step until it locks up, hoping that I've guessed
right.

The frustrating part is that most of the time my guesses are wrong.

It would be really nice if I could send the python process some signal
which would cause it to print the current stacktrace and exit
immediately. That way I would quickly be able to pinpoint where in the
code the deadlock happens. Java has a somewhat similar feature where
you can send a running VM process a SIGQUIT, to which it will respond
by dumping all current threads and lots of other information on stdout.

Is this possible somehow?

Oct 6 '06 #1
6 1441
Did you try using the signal module? If not, a basic example is here
<http://docs.python.org/lib/node546.htmlwhich may need to be
extended.

/Jean Brouwers
an*********@gmail.com wrote:
Hi all

I'm currently having some issues with a process getting deadlocked. The
problem is that the only way I can seem to find information about where
it deadlocks is by making a wild guess, insert a pdb.set_trace() before
this point, and then step until it locks up, hoping that I've guessed
right.

The frustrating part is that most of the time my guesses are wrong.

It would be really nice if I could send the python process some signal
which would cause it to print the current stacktrace and exit
immediately. That way I would quickly be able to pinpoint where in the
code the deadlock happens. Java has a somewhat similar feature where
you can send a running VM process a SIGQUIT, to which it will respond
by dumping all current threads and lots of other information on stdout.

Is this possible somehow?
Oct 6 '06 #2
<an*********@gmail.comwrote:
Hi all

I'm currently having some issues with a process getting deadlocked. The
problem is that the only way I can seem to find information about where
it deadlocks is by making a wild guess, insert a pdb.set_trace() before
this point, and then step until it locks up, hoping that I've guessed
right.

The frustrating part is that most of the time my guesses are wrong.
Welcome to the wonderful world of crash and burn....
>
It would be really nice if I could send the python process some signal
which would cause it to print the current stacktrace and exit
immediately. That way I would quickly be able to pinpoint where in the
code the deadlock happens. Java has a somewhat similar feature where
you can send a running VM process a SIGQUIT, to which it will respond
by dumping all current threads and lots of other information on stdout.

Is this possible somehow?
Have you tried to sprinkle your code with print statements of the "We get here
No: 7" kind - you can get quite a good idea of what is going on if you do, and
if there are threads running - the results are often surprisingly insightful...

- Hendrik

Oct 7 '06 #3

MrJean1 wrote:
Did you try using the signal module? If not, a basic example is here
<http://docs.python.org/lib/node546.htmlwhich may need to be
extended.
I looks useful. I gave it a try, and the only weakness it has is that
when my process locks, it locks so badly that it doesn't respond to
CTRL-C, or any other signal. But by sending it a SIGQUIT which causes
it to dump the current state, and then kill it, I get the dump I need.

This is actually not a multi-threaded app. It's an application which
uses a SQL DB. The problem I was having was that I had a cursor which
started a transaction, and then never finished. Then some other cursor
came along and tried to perform a delete table, and they both locked
up. The cursor isn't ending it's transaction, and the transaction
prevents the delete table from being executed. Luckily Postgresql
allows me to list current activity, otherwise I would have been
scratching my head still.

Using logging or print statements to debug this sort of things is
highly unsatisfactory. I think the way Java uses SIGQUIT is pretty
neat, are there any reasons why Python can't adopt something similar?

Oct 7 '06 #4
an*********@gmail.com wrote:
Hi all

I'm currently having some issues with a process getting deadlocked. The
problem is that the only way I can seem to find information about where
it deadlocks is by making a wild guess, insert a pdb.set_trace() before
this point, and then step until it locks up, hoping that I've guessed
right.

The frustrating part is that most of the time my guesses are wrong.

It would be really nice if I could send the python process some signal
which would cause it to print the current stacktrace and exit
immediately. That way I would quickly be able to pinpoint where in the
code the deadlock happens. Java has a somewhat similar feature where
you can send a running VM process a SIGQUIT, to which it will respond
by dumping all current threads and lots of other information on stdout.

Is this possible somehow?
Check out the sys._current_frames() function, new in Python 2.5:
http://docs.python.org/lib/module-sys.html#l2h-5122

Hope this helps,
Ziga

Oct 7 '06 #5
Dennis Lee Bieber wrote:
On 6 Oct 2006 12:59:31 -0700, an*********@gmail.com declaimed the
following in comp.lang.python:
I'm currently having some issues with a process getting deadlocked. The
problem is that the only way I can seem to find information about where
it deadlocks is by making a wild guess, insert a pdb.set_trace() before
this point, and then step until it locks up, hoping that I've guessed
right.
I presume the process is using threads? If it is truly deadlocked,
then you must have some mutual calls to lock objects somewhere... It
would seem that rather than just randomly inserting debug statements you
should surround each call to a lock with statements.

print "Locking xyz"
xyz.acquire() #or whatever the syntax is
print "Locked xyz"

print "Releasing xyz"
xyz.release()
print "Released xyz"
You'd need something like that around any potentially blocking
operation -- queue operations, subprocess operations, socket
operations... Rather than print statements you may wish to implement it
via the logging module.
If you don't mind a potentially large log file, use the pyconquer
module I maintain here: http://projects.amor.org/misc/wiki/PyConquer
which uses settrace to do the logging in a much more readable and
manageable way than printlining. Try an initial run using the default
settings to narrow down the culprit, and then a run with C events
turned on if the first run wasn't enough. It should help out even if
your program is not multi-threaded, but it realy shines with threads.
:)
Robert Brewer
System Architect
Amor Ministries
fu******@amor.org

P.S. Oh, and ignore the times in the output for now; that's still work
in progress.

Oct 7 '06 #6
an*********@gmail.com wrote:
MrJean1 wrote:
Did you try using the signal module? If not, a basic example is here
<http://docs.python.org/lib/node546.htmlwhich may need to be
extended.

I looks useful. I gave it a try, and the only weakness it has is that
when my process locks, it locks so badly that it doesn't respond to
CTRL-C, or any other signal. But by sending it a SIGQUIT which causes
it to dump the current state, and then kill it, I get the dump I need.
The Ctrl-C signal SIGINT is caught by Python by default and the signal
handler
raises a KeyboardInterrupt exception. For any other signals, the
signal is caught
but the signal handler is not called until Python returns to the main
loop.

Therefore, if some extension -like Postgresql in this case- is busy or
hangs, nothing
will happen until Python regains control.

>
This is actually not a multi-threaded app. It's an application which
uses a SQL DB. The problem I was having was that I had a cursor which
started a transaction, and then never finished. Then some other cursor
came along and tried to perform a delete table, and they both locked
up. The cursor isn't ending it's transaction, and the transaction
prevents the delete table from being executed. Luckily Postgresql
allows me to list current activity, otherwise I would have been
scratching my head still.

Using logging or print statements to debug this sort of things is
highly unsatisfactory. I think the way Java uses SIGQUIT is pretty
neat, are there any reasons why Python can't adopt something similar?
I can not anwer that.

/Jean Brouwers

Oct 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3990
by: ken | last post by:
hello, i'm writing a c program on a linux system. i'm debugging a segmentation fault but i don't want it to dump a core file because the memory footprint of the program is over 300Mb and i don't...
1
2367
by: Adam Smith | last post by:
When executing ExecuteXmlReader() against a table where records are being inserted, I get: 9/5/2003 8:39:47 AM Transaction (Process ID 66) was deadlocked on lock resources with another process...
3
5977
by: Nhi Lam | last post by:
Hi, I understand that there are 3 modes in which I can configure the SessionStateModule. What I need is an out of process Session State store with fail over support. The "SQL Server Mode" seems...
4
2304
by: Chad Crowder | last post by:
I've taken a look at this article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp12282000.asp which someone posted a month or so ago regarding setting up SQL...
1
1665
by: bmmodi | last post by:
Hello, We have three webservers that host the same web application (written in VB.NET running on .NET Framework 1.0 SP2). We receive the following error (aspnet_wp.exe (PID: 1864) was recycled...
2
2821
by: Antonio Concepcion | last post by:
Hi! We have an ASP.NET web site experiencing errors saying that aspnet_wp.exe got into a deadlock state and was recycled. Specifically the Client browser gets the following message: ...
10
3478
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
6
3765
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
4
14705
weaknessforcats
by: weaknessforcats | last post by:
Design Patterns State Often computer software operates based on a condition called a state. These states traditionally have been implemented using a switch statement. The cases of the switch...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.