473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to troubleshoot hanging script?

kj


Hi! I have a Pythonoob question.

I have a script that hangs indefinitely at random times; the only
thing to do at this point is to kill it.

I'm looking for suggestions on how to troubleshoot and debug the
problem.

I'm not even sure of where exactly the script is hanging, though
I suspect it is right around when it tries to read from a pipe
(generated by popen). (I arrived at this guess by putting print
statements all over the place, but I'm not sure this is a very
reliable way to pinpoint the error.)

So the first thing I'd like to do is find out exactly where the
script is hanging. It would be nice if I could just hit Ctrl-C
(which sends SIGINT from the terminal) when the script is hanging,
to kill it and get a backtrace, but when this script hangs it
becomes unresponsive to Ctrl-C! The only way to kill it is with
something like

% pkill -KILL my_script.py

or even

% pkill -TERM my_script.py

....or -ABRT or -QUIT. I tried to exploit this by adding this to the
script:

import signal

def term_handler(si gnum, frame):
raise KeyboardInterru pt

signal.signal(s ignal.SIGTERM, term_handler)

....but this did not help at all; in fact, after this addition, the script
no longer responded to pkill -TERM.

TIA!

Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Aug 5 '08 #1
2 8322
Hi,

Just a thought, I'm not sure it's the best way.
You can start an alarm just before the line you *think* it's wrong and
cancel it after that. If it's activated then you probably have
pinpointed the location. Have a look at the signals module
http://docs.python.org/lib/module-signal.html, the alarm function.

Hope it helps.

kj wrote:
Hi! I have a Pythonoob question.

I have a script that hangs indefinitely at random times; the only
thing to do at this point is to kill it.

I'm looking for suggestions on how to troubleshoot and debug the
problem.

I'm not even sure of where exactly the script is hanging, though
I suspect it is right around when it tries to read from a pipe
(generated by popen). (I arrived at this guess by putting print
statements all over the place, but I'm not sure this is a very
reliable way to pinpoint the error.)

So the first thing I'd like to do is find out exactly where the
script is hanging. It would be nice if I could just hit Ctrl-C
(which sends SIGINT from the terminal) when the script is hanging,
to kill it and get a backtrace, but when this script hangs it
becomes unresponsive to Ctrl-C! The only way to kill it is with
something like

% pkill -KILL my_script.py

or even

% pkill -TERM my_script.py

...or -ABRT or -QUIT. I tried to exploit this by adding this to the
script:

import signal

def term_handler(si gnum, frame):
raise KeyboardInterru pt

signal.signal(s ignal.SIGTERM, term_handler)

...but this did not help at all; in fact, after this addition, the script
no longer responded to pkill -TERM.

TIA!

Kynn
Aug 6 '08 #2
kj a écrit :
Hi! I have a Pythonoob question.

I have a script that hangs indefinitely at random times; the only
thing to do at this point is to kill it.

I'm looking for suggestions on how to troubleshoot and debug the
problem.

I'm not even sure of where exactly the script is hanging, though
I suspect it is right around when it tries to read from a pipe
(generated by popen). (I arrived at this guess by putting print
statements all over the place, but I'm not sure this is a very
reliable way to pinpoint the error.)

So the first thing I'd like to do is find out exactly where the
script is hanging. It would be nice if I could just hit Ctrl-C
(which sends SIGINT from the terminal) when the script is hanging,
to kill it and get a backtrace, but when this script hangs it
becomes unresponsive to Ctrl-C!
Pretty often, this kind of behaviour is related to a catch-all (or at
least a 'catch-too-much') except clause that doesn't re-raise.
wrt/ debugging, there's a command-line debugger named pdb in the stdlib.
Aug 6 '08 #3

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

Similar topics

4
1923
by: frank | last post by:
Hi all, I have a largish asp-driven site that's crashing intermittently in a way that's just causing me to scratch my head a lot. I've not seen this happen in about five years of developing asp apps. This is what happens: asp v3 access 2000 database win 2003 server. 1. It runs on my server and on my test server just fine. Complete test of
14
2006
by: Pascal Damian | last post by:
My HTML pages have a <SCRIPT SRC=http://remote/script> at the top'ish of each page. Sometimes the remote host (probably due to heavy load or flaky network connectivity) doesn't respond for a long time. This causes the whole page to appear hanging without anything loading. Is there some trick I can use with settimeout() so that if the remote script cannot be loaded after, say, 30 seconds, then I can tell the page/browser to cancel loading...
14
19800
by: Rochester | last post by:
Hi, I just found out that the general open file mechanism doesn't work for named pipes (fifo). Say I wrote something like this and it simply hangs python: #!/usr/bin/python import os
1
1536
by: Azzuron | last post by:
Hello everyone. We have a script with a periodic hanging query. What i mean, is that it sometimes seems to work, it sometimes seems to just hang up and never finish. I have identified the query to be: Update tp set tp.descrip = bb.description from .dbo.products as tp, brokerbin.dbo. as bb where tp.descrip IS NULL and tp.code = bb. and bb.Cond = 'NEW';
3
1519
by: jaimebienlesfruits | last post by:
Hi, I'm working on a website and I keep getting this error "SimpleswapSetup is not defined". I'm not really fluent in JS, so I haven't a clue what's going on. Here's some code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head>
6
8527
by: Adrian | last post by:
Hi there My VB Code looks something like that: ************************************************************** Dim oShellApplication = CreateObject("Shell.Application") Dim objWindow For Each objWindow In oShellApplication.Windows() 'do stupid things with IE Next objWindow
1
3070
by: =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= | last post by:
Hello guys, I was wondering if anybody here had implemented a solution where Tables are aligned according to what the hanging indent tells us when there is a potential for the table overflowing in the right margin or out of the page. I did some research a while back and came to the conclusion at that time that it wasn't possible to have both (either we align on the hanging indent and if there is a potential for a table to be 6.75
5
2632
by: PJ6 | last post by:
I can't figure this out. I have several references to style sheets and javascript files in my page header, the contents of which are served dynamically by my httphandler that serves *.res requests. The handler works most of the time, but occasionally the page load hangs on the loading of the last .res reference for a javascript file (Fiddler shows me this), and when I stop the load in the browser, I get this error message: A first chance...
0
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9857
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7404
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.