[Tutor] Threaded Script Runs Find in IDLE, Never Terminates from Windows Command Prompt

Gooch, John John.Gooch at echostar.com
Wed Jan 19 15:59:00 CET 2005


I have a threaded python ( Python 2.3.4 ) script that runs perfectly on
Windows 2000 Server SP4 when it is executed from IDLE ( i.e. press 'F5' from
the editor ), the threads do their work, halt, and the 'join' command picks
them up. When I run the same script from windows command line ( cmd.exe ),
it appears to work normally until the last thread is 'joined'. What happens
at that point is it does not execute the any lines after the join command,
and will stay in the position indefinitely. 

Do I need to alter the script to run from the command line, or perhaps add
some parameters to have it terminate successfully? Once this issue is
resolved, the script will run daily via a scheduling program we use in our
company, and the exit code of the script tells the scheduler whether the
script completed its task successfully or not. 

Here is the 'code block' of my script that clean up  the threads via .join:

    for workerThread in ThreadGroup:
        #timeout will difference between ( start time + 4 hours ) and
current time
        #unless current time is greater than that, in which case the
        #thread gets one second to join
        #For example, if the current time if 30 minutes less than the
endTime
        #time, then the thread has a timeout to 'join' of 30 minutes 
        #timeout = endTime - time.time()
        #if ( timeout < 0 ):
        #    timeout = 1
        if debug:
            print "Joining "+workerThread.getName()+".\n"
        workerThread.join()
        if debug:
            print "Thread "+workerThread.getName()+" successfully joined."
 

I run it with 3 threads, from IDLE it will close all 3 and exit normally,
from the command prompt it prints the "successfully joined" for the first
two, but hangs after printing "Joining Thread 3". The command line syntax is
"c:"\python23\python.exe test.py", I have also tried
"c:\python23\pythonw.exe test.py", but that just adds an entry in Windows
task manager and sits there forever also. 

Thank You, 

 



More information about the Tutor mailing list