[python-win32] Process creation hang up

Misha Verplak mvmisha@yahoo.com
Thu, 19 Dec 2002 01:01:48 -0000


So a solution for this might involve a simple message pump in the program,
while waiting for the result file?

Bill, I misread your first post to mean that program.exe is an external
program to your python program :)

Kind regards,
Misha

----- Original Message -----
From: Mark Hammond
To: 'Bill Taylor' ; python-win32@python.org
Sent: 19 December 2002 00:06
Subject: RE: [python-win32] Process creation hang up


It sounds to me like program.exe needs to be running a message loop.  As
soon as it displays a window it stops freezing (and a window implies a
message loop) and you are trying to use DDE, which is also message based.

Mark.
-----Original Message-----
From: python-win32-admin@python.org [mailto:python-win32-admin@python.org]On
Behalf Of Bill Taylor
Sent: Thursday, 19 December 2002 9:21 AM
To: 'python-win32@python.org'
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:

Spawnl
==================================================
os.spawnl(os.P_WAIT, programPathName)
==================================================

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

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

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

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

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