[python-win32] Process creation hang up - Part 2
Bill Taylor
BTaylor@harlandfs.com
Thu, 19 Dec 2002 12:08:59 -0800
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C2A79A.779DD5F0
Content-Type: text/plain;
charset="iso-8859-1"
I failed to give the complete scenario on this and also make clear a few
other things.
1. This all begins with an MFC app launching my python scripts. So, again,
the complete progression is:
MFC app launches python scripts
python scripts call program.exe
program.exe calls login.exe
login.exe presents login window to user
user enters login info
program.exe hangs
python scripts timeout waiting for program.exe to write result.txt; python
scripts present message window to user.
program.exe "un-hangs"; writes result.txt
2. Program.exe and login.exe are third party apps in which I do not have
access to that code. When program.exe is run as a stand alone app, it works
fine, creating result.txt.
Sorry for the omissions - thanks again for your suggestions.
Bill
-----Original Message-----
From: Bill Taylor
Sent: Wednesday, December 18, 2002 2:21 PM
To: 'python-win32@python.org'
Subject: 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
------_=_NextPart_001_01C2A79A.779DD5F0
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.00.3315.2870" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>I
failed to give the complete scenario on this and also make clear a few other
things.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>1.
This all begins with an MFC app launching my python scripts. So,
again, the complete progression is:</SPAN></FONT></DIV></SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>MFC
app launches python scripts</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>python
scripts call program.exe</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002>program.exe calls login.exe</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002>login.exe presents login window to
user</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>user
enters login info</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002>program.exe hangs</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>python
scripts timeout waiting for program.exe to write result.txt; python scripts
present message window to user.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002>program.exe "un-hangs"; writes
result.txt</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002><FONT
color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>2. Program.exe
and login.exe are third party apps in which I do not have access to that
code. When program.exe is run as a stand alone app, it works fine,
creating result.txt.</SPAN></FONT></SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=237115219-19122002>Sorry
for the omissions - thanks again for your suggestions.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=237115219-19122002>Bill</SPAN></FONT></DIV>
<DIV align=left class=OutlookMessageHeader dir=ltr><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Bill Taylor <BR><B>Sent:</B>
Wednesday, December 18, 2002 2:21 PM<BR><B>To:</B>
'python-win32@python.org'<BR><B>Subject:</B> Process creation hang
up<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>Hi
all,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>Sorry this is
lengthy and wordy... but does anyone have experience with process creation?<SPAN
style="mso-spacerun: yes"> </SPAN>I’m having problems with my child
process hanging.<SPAN style="mso-spacerun: yes"> </SPAN>Could be I’m a
rookie (I am) missing the boat on something simple… or I’m just an idiot… or
both (likely) :)</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>Here’s my
scenario:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>I need to call an
executable within my Python code – let’s call this program.exe.<SPAN
style="mso-spacerun: yes"> </SPAN>Program.exe in turn calls a login
executable – let’s call this login.exe.<SPAN style="mso-spacerun: yes">
</SPAN>Program.exe calls login.exe opening a DDE channel.<SPAN
style="mso-spacerun: yes"> </SPAN>Login.exe presents a login window to a
user.<SPAN style="mso-spacerun: yes"> </SPAN>The user enters user ID and
password and then program.exe logs into a server database.<SPAN
style="mso-spacerun: yes"> </SPAN>Once connected, program.exe gathers
database information and writes it to a text file named result.txt back on the
calling machine.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>Here’s my
problem:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>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.<SPAN style="mso-spacerun: yes"> </SPAN>Immediately
after calling program.exe, my code goes into a time.sleep loop looking for
result.exe.<SPAN style="mso-spacerun: yes"> </SPAN>When result.exe is not
found within a specified time, I present a message to the user to
terminate.<SPAN style="mso-spacerun: yes"> </SPAN>As soon as this message
is presented, program.exe “un-hangs” and completes execution, writing result.txt
to the calling machine.<SPAN style="mso-spacerun: yes"> </SPAN>So, it
appears my code has some sort of lock on the processor (possibly my time.sleep
loop) preventing program.exe from processing.<SPAN
style="mso-spacerun: yes"> </SPAN>Any clues on this?</SPAN></FONT><FONT
face=Arial size=2><SPAN class=472114621-18122002></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>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.<SPAN style="mso-spacerun: yes"> </SPAN>Here’s
my basic calls:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>Spawnl</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>==================================================</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>os.spawnl(os.P_WAIT,
programPathName)</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>==================================================</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>ShellExecute</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>==================================================</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>win32api.ShellExecute(0, None, programPathName, "",
programPath, 1)</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>==================================================</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>CreateProcess</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>==================================================</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=472114621-18122002>si =
win32process.STARTUPINFO()</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>win32process.CreateProcess(None, #
module</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
programPathName, #command line</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
None, #process security attributes</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
None, #thread security attributes</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
0, #handle inheritance flag</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
win32con.NORMAL_PRIORITY_CLASS, #creation flags</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
None, # process new environment setting</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
programPath, #start directory</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>
si) #STARTUPINFO object specifying window appearance</SPAN></FONT></DIV>
<DIV><SPAN class=472114621-18122002><FONT face=Arial
size=2>==================================================</FONT></SPAN></DIV>
<DIV><SPAN class=472114621-18122002></SPAN> </DIV>
<DIV><SPAN class=472114621-18122002><FONT face=Arial size=2>wait
loop</FONT></SPAN></DIV>
<DIV><SPAN class=472114621-18122002><FONT face=Arial
size=2>==================================================</FONT></SPAN></DIV>
<DIV><SPAN class=472114621-18122002><FONT face=Arial size=2>while not
os.path.exists(fileName) and wait <
maxWait:<BR> wait +=
1<BR>
time.sleep(1)<BR> <BR>
if wait >=
maxWait:<BR>
#Timeout
error<BR>
message = "Cannot find file " + fileName + "\nDo you want to continue
searching?"<BR>
ret = DisplayMessageBox(message, "File Search Timeout Message",
"YESNO")<BR>
if ret ==
1:<BR>
wait = 0<BR>
else:</FONT></SPAN></DIV>
<DIV><SPAN class=472114621-18122002><FONT face=Arial
size=2>
#terminate</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=472114621-18122002>==================================================</SPAN></FONT></DIV>
<DIV><SPAN class=472114621-18122002><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=472114621-18122002><FONT face=Arial size=2>Any suggestions/help
are/is much appreciated!</FONT></DIV>
<P class=MsoNormal><FONT size=2><FONT face=Arial>Thanks in advance folks<SPAN
class=472114621-18122002>,</SPAN></FONT></FONT></P>
<P class=MsoNormal><FONT size=2><FONT face=Arial><SPAN
class=472114621-18122002>Bill
Taylor</SPAN></FONT></FONT></P></SPAN></BODY></HTML>
------_=_NextPart_001_01C2A79A.779DD5F0--