Debugging multithreaded scrips

E

Elbert Lev

I started with Python two weeks ago and already saved some time and
efforts while writing 2 programs:
1. database extraction and backup tool, which runs once a month and
creates a snapshot of important data, compresses and saves it.
2. pop3 "watchdog", which reads e-mail from a pop3 mailbox and in the
case there is no mail sends e-mail messages to technicians. (the
presence of e-mail in the mailbox tells that the system I'm monitoring
works fine).

Both programs run on W2K as services and I'm very satisfied with
Python.

I have two questions.

1. How one can debug multithreaded Python programs?

2. Is dynamic typing blessing or an opposite thing?

None of the debugging tools seems to be able to debug multithreaded
programs. I believe that all of them are based on pdb.py module.
pdb.py module also fails to stop on a breakpoint, which is in a
function, executed not in the main thread.

In multithreaded program you have to run some sort of a message loop
in the end of the main thread, waiting for some sort of termination
event (f.e. keyboard input or external signal). After receiving this
signal you terminate the thread(s) and exit the main thread.
raw_input("...") is also fine for signaling purposes (I use
kbhit/getch/sleep on Windows).

Pythonwin does not work with raw_input and threads - it creates system
modal dialog box and blocks its own windows updates (including the
interpreter window).

So I had to resort to UNIVERSAL print statement. Tell me about stone
age!

How are you debugging multithreaded Python programs???


Dynamic typing.

The problem: in languages like C++ or Java typos are caught by
compiler and have no way to break the run time. Not that good in
Python. Consider this:

a1=5
a2=6
def f(p1, p2): return p1 + p2
print f(a1, a2)

the program works fine for half a year, but then at 1:30 AM your boss
tells you that he wants this line printed 2 times. You change the
program:

a1=5
a2=6
def f(p1, p2): return p1 + p2
print f(a1, a2)
print f(a1, a3)

and go home. At 5:25 AM boss calls and tells you - you know what.

Such situations are impossible in compiled statically typed languages.

Is dynamic typing blessing or an opposite thing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top