[python-win32] Process creation hang up
robin and jim
robinjim@earthlink.net
Wed, 18 Dec 2002 16:21:47 -0700
This is a multi-part message in MIME format.
------=_NextPart_000_000B_01C2A6B1.8FD3CD80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Is it possible that program.exe is "blocking" because it is waiting for =
some event (user input perhaps) that is cleared when the user responds =
to the "terminate" query?
----- Original Message -----=20
From: Bill Taylor=20
To: 'python-win32@python.org'=20
Sent: Wednesday, December 18, 2002 3:20 PM
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
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
os.spawnl(os.P_WAIT, programPathName)
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
ShellExecute
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
win32api.ShellExecute(0, None, programPathName, "", programPath, 1)
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
CreateProcess
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
si =3D 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
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
wait loop
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
while not os.path.exists(fileName) and wait < maxWait:
wait +=3D 1
time.sleep(1)
=20
if wait >=3D maxWait:
#Timeout error
message =3D "Cannot find file " + fileName + "\nDo you =
want to continue searching?"
ret =3D DisplayMessageBox(message, "File Search Timeout =
Message", "YESNO")
if ret =3D=3D 1:
wait =3D 0
else:
#terminate
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
Any suggestions/help are/is much appreciated!
Thanks in advance folks,
Bill Taylor
------=_NextPart_000_000B_01C2A6B1.8FD3CD80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Comic Sans MS" size=3D2>Is it possible that =
program.exe is=20
"blocking" because it is waiting for some event (user input perhaps) =
that is=20
cleared when the user responds to the "terminate" query?</FONT></DIV>
<DIV><FONT face=3D"Comic Sans MS" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Comic Sans MS" size=3D2></FONT> </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A title=3DBTaylor@harlandfs.com =
href=3D"mailto:BTaylor@harlandfs.com">Bill=20
Taylor</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dpython-win32@python.org=20
=
href=3D"mailto:'python-win32@python.org'">'python-win32@python.org'</A> =
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, December 18, =
2002 3:20=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [python-win32] Process =
creation=20
hang up</DIV>
<DIV><FONT face=3D"Comic Sans MS" size=3D2></FONT><FONT face=3D"Comic =
Sans MS"=20
size=3D2></FONT><FONT face=3D"Comic Sans MS" =
size=3D2></FONT><BR></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D472114621-18122002>Hi=20
all,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D472114621-18122002>Sorry this is=20
lengthy and wordy... but does anyone have experience with process=20
creation?<SPAN style=3D"mso-spacerun: yes"> </SPAN>I=92m having =
problems=20
with my child process hanging.<SPAN style=3D"mso-spacerun: yes"> =
</SPAN>Could be I=92m a rookie (I am) missing the boat on something =
simple=85 or=20
I=92m just an idiot=85 or both (likely) :)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D472114621-18122002>Here=92s my=20
scenario:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D472114621-18122002>I =
need to call an=20
executable within my Python code =96 let=92s call this =
program.exe.<SPAN=20
style=3D"mso-spacerun: yes"> </SPAN>Program.exe in turn calls a =
login=20
executable =96 let=92s call this login.exe.<SPAN =
style=3D"mso-spacerun: yes"> =20
</SPAN>Program.exe calls login.exe opening a DDE channel.<SPAN=20
style=3D"mso-spacerun: yes"> </SPAN>Login.exe presents a login =
window to a=20
user.<SPAN style=3D"mso-spacerun: yes"> </SPAN>The user enters =
user ID and=20
password and then program.exe logs into a server database.<SPAN=20
style=3D"mso-spacerun: yes"> </SPAN>Once connected, program.exe =
gathers=20
database information and writes it to a text file named result.txt =
back on the=20
calling machine.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D472114621-18122002>Here=92s my=20
problem:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D472114621-18122002>When =
I use=20
win32api.WinExec(programPathName), program.exe is called, login.exe is =
called,=20
login window is presented to the user, user enters login information, =
and then=20
program.exe hangs.<SPAN style=3D"mso-spacerun: yes"> =
</SPAN>Immediately=20
after calling program.exe, my code goes into a time.sleep loop looking =
for=20
result.exe.<SPAN style=3D"mso-spacerun: yes"> </SPAN>When =
result.exe is=20
not found within a specified time, I present a message to the user to=20
terminate.<SPAN style=3D"mso-spacerun: yes"> </SPAN>As soon as =
this=20
message is presented, program.exe =93un-hangs=94 and completes =
execution, writing=20
result.txt to the calling machine.<SPAN style=3D"mso-spacerun: =
yes"> =20
</SPAN>So, it appears my code has some sort of lock on the processor =
(possibly=20
my time.sleep loop) preventing program.exe from processing.<SPAN=20
style=3D"mso-spacerun: yes"> </SPAN>Any clues on =
this?</SPAN></FONT><FONT=20
face=3DArial size=3D2><SPAN =
class=3D472114621-18122002></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D472114621-18122002>Also, I=92ve tried=20
the os.spawn functions, win32api.ShellExecute, and =
win32process.CreateProcess=20
with several different parameter settings on each and I get similar =
behavior=20
except with all of these I don't get as far as with WinExec in that=20
login.exe=92s login window never even displays.<SPAN=20
style=3D"mso-spacerun: yes"> </SPAN>Here=92s my basic=20
calls:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002>Spawnl</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002>os.spawnl(os.P_WAIT,=20
programPathName)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002>ShellExecute</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002>win32api.ShellExecute(0, None, =
programPathName, "",=20
programPath, 1)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002>CreateProcess</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D472114621-18122002>si =
=3D=20
win32process.STARTUPINFO()</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D472114621-18122002>win32process.CreateProcess(None, #=20
module</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
programPathName, #command line</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
None, #process security attributes</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
None, #thread security attributes</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
0, #handle inheritance flag</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
win32con.NORMAL_PRIORITY_CLASS, #creation flags</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
None, # process new environment setting</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
programPath, #start directory</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002> &nbs=
p;  =
; =
=20
si) #STARTUPINFO object specifying window =
appearance</SPAN></FONT></DIV>
<DIV><SPAN class=3D472114621-18122002><FONT face=3DArial=20
=
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D</FONT></SPAN></DIV>
<DIV><SPAN class=3D472114621-18122002></SPAN> </DIV>
<DIV><SPAN class=3D472114621-18122002><FONT face=3DArial size=3D2>wait =
loop</FONT></SPAN></DIV>
<DIV><SPAN class=3D472114621-18122002><FONT face=3DArial=20
=
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D</FONT></SPAN></DIV>
<DIV><SPAN class=3D472114621-18122002><FONT face=3DArial =
size=3D2>while not=20
os.path.exists(fileName) and wait <=20
maxWait:<BR> wait +=3D=20
1<BR> =20
=
time.sleep(1)<BR> &n=
bsp; <BR> =20
if wait >=3D=20
=
maxWait:<BR> &=
nbsp;=20
#Timeout=20
=
error<BR> &nbs=
p;=20
message =3D "Cannot find file " + fileName + "\nDo you want to =
continue=20
=
searching?"<BR> &nbs=
p; =20
ret =3D DisplayMessageBox(message, "File Search Timeout Message",=20
=
"YESNO")<BR> &=
nbsp;=20
if ret =3D=3D=20
=
1:<BR> &=
nbsp; =20
wait =3D =
0<BR> =20
else:</FONT></SPAN></DIV>
<DIV><SPAN class=3D472114621-18122002><FONT face=3DArial=20
=
size=3D2> &nbs=
p; =20
#terminate</FONT></SPAN></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
=
class=3D472114621-18122002>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D</SPAN></FONT></DIV>
<DIV><SPAN class=3D472114621-18122002><FONT face=3DArial=20
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D472114621-18122002><FONT face=3DArial size=3D2>Any=20
suggestions/help are/is much appreciated!</FONT></DIV>
<P class=3DMsoNormal><FONT size=3D2><FONT face=3DArial>Thanks in =
advance folks<SPAN=20
class=3D472114621-18122002>,</SPAN></FONT></FONT></P>
<P class=3DMsoNormal><FONT size=3D2><FONT face=3DArial><SPAN=20
class=3D472114621-18122002>Bill=20
Taylor</SPAN></FONT></FONT></P></BLOCKQUOTE></SPAN></BODY></HTML>
------=_NextPart_000_000B_01C2A6B1.8FD3CD80--