[python-win32] Process creation hang up

Misha Verplak mvmisha@yahoo.com
Wed, 18 Dec 2002 23:25:32 -0000

Hi Bill

To help pin down the problem, you could try:

os.startfile()  I am guessing it will behave exactly the same.

Simplify your wait routine by removing the os.path.exists() call, and just
sleep for a fixed length of time before displaying the message. Does the
problem still occur?

Try a print statement in your loop, does that prevent the "hang"?

Replace time.sleep() with win32api.Sleep(), still a problem? Try a different
way of delaying, eg. a messagebox straight after running program.exe, see if
program still hangs around after login.

Choose a different way of indicating timeout, eg. win32api.MessageBox() or
simply a print statement and get raw input, or another sleep...

Your program.exe could be waiting on a file lock for the results, or on
standard output to be flushed/released (whatever that might mean, but I've
noticed something similar with this), or on the sleep statements.

There are other possibilities, eg. your python program and program.exe both
waiting on the same message loop, but this is rather unlikely from your

Kind regards,

----- Original Message -----
From: Bill Taylor
To: 'python-win32@python.org'
Sent: 18 December 2002 22:20
Subject: [python-win32] Process creation hang up

Hi all,

Sorry this is lengthy and wordy... but does anyone have experience with
process creation?  I'm having problems with my child process hanging.  Could
be I'm a rookie (I am) missing the boat on something simple. or I'm just an
idiot. or both (likely) :)

Here's my scenario:
I need to call an executable within my Python code - let's call this
program.exe.  Program.exe in turn calls a login executable - let's call this
login.exe.  Program.exe calls login.exe opening a DDE channel.  Login.exe
presents a login window to a user.  The user enters user ID and password and
then program.exe logs into a server database.  Once connected, program.exe
gathers database information and writes it to a text file named result.txt
back on the calling machine.

Here's my problem:
When I use win32api.WinExec(programPathName), program.exe is called,
login.exe is called, login window is presented to the user, user enters
login information, and then program.exe hangs.  Immediately after calling
program.exe, my code goes into a time.sleep loop looking for result.exe.
When result.exe is not found within a specified time, I present a message to
the user to terminate.  As soon as this message is presented, program.exe
"un-hangs" and completes execution, writing result.txt to the calling
machine.  So, it appears my code has some sort of lock on the processor
(possibly my time.sleep loop) preventing program.exe from processing.  Any
clues on this?

Also, I've tried the os.spawn functions, win32api.ShellExecute, and
win32process.CreateProcess with several different parameter settings on each
and I get similar behavior except with all of these I don't get as far as
with WinExec in that login.exe's login window never even displays.  Here's
my basic calls:

os.spawnl(os.P_WAIT, programPathName)

win32api.ShellExecute(0, None, programPathName, "", programPath, 1)

si = win32process.STARTUPINFO()
win32process.CreateProcess(None, # module
                                           programPathName, #command line
                                           None, #process security
                                           None, #thread security attributes
                                           0, #handle inheritance flag
#creation flags
                                           None, # process new environment
                                           programPath, #start directory
                                           si) #STARTUPINFO object
specifying window appearance

wait loop
while not os.path.exists(fileName) and wait < maxWait:
        wait += 1

        if wait >= maxWait:
            #Timeout error
            message = "Cannot find file " + fileName + "\nDo you want to
continue searching?"
            ret = DisplayMessageBox(message, "File Search Timeout Message",
            if ret == 1:
                wait = 0

Any suggestions/help are/is much appreciated!
Thanks in advance folks,
Bill Taylor