Threading and Windows.
Jorge Godoy
godoy at metalab.unc.edu
Tue Sep 30 12:01:46 EDT 2003
Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:
> Jorge Godoy fed this fish to the penguins on Tuesday 30 September 2003
> 04:08 am:
>
>>
>> I thought the same thing and even thought I was using os.spawnv() in a
>> wrong way. Even with the 'P_NOWAIT' flag it still hangs.
>>
> I may have found the problem (surprised the experts didn't catch it).
>
> From your initial post:
> os.spawnv('P_NOWAIT', 'another.py', ['another.py', parameters])
>
> You specified P_NOWAIT as a STRING. It should be a constant /in/ the os
> module.
The most interesting thing is that I get an error in Windows but I
don't get such an error in Linux.
This is the output on an interactive session running on Linux:
>>> import os
>>> os.spawnv(os.P_NOWAIT, 'ls', ['ls', '*.py'])
790
>>> os.spawnv('os.P_NOWAIT', 'ls', ['ls', '*.py'])
127
>>> os.spawnv('P_NOWAIT', 'ls', ['ls', '*.py'])
127
>>> os.spawnv(os.P_WAIT, 'ls', ['ls', '*.py'])
127
>>> os.spawnv(os.P_NOWAIT, 'ls', ['ls', '*.py'])
795
>>>
Now, on the Windows box:
>>> import os
>>> os.spawnv(os.P_NOWAIT, 'c:/python22/python.exe', ['c:/python22/python.exe'])
112
>>> os.spawnv('P_NOWAIT', 'c:/python22/python.exe', ['c:/python22/python.exe'])
Traceback (most recent call last):
File "<pyshell#6>", line 1, in ?
os.spawnv('P_NOWAIT', 'c:/python22/python.exe', ['c:/python22/python.exe'])
TypeError: an integer is required
>>>
And this is how I found out where was the problem.
> Note the use of os.P_NOWAIT rather than your 'P_NOWAIT'
It indeed work. I'll replace the '1's with it on the code.
> If you want portability, this may be the way to go -- I just changed
> the spawnv() call above from "./t1.py" to "python t1.py" and it still
> ran on Linux. I'd presume it would also run on Windows (I'm not going
> to reboot just to prove that)
Just if it is in the PATH, I suppose. I don't believe Windows scans
through all directories if it can't find the executable.
> NO THREADS NEEDED.
:-)
Solving the problem with os.P_NOWAIT is better than using threads. ;-)
The problem was my misinterpretation of the docs (or maybe they don't
make it explicit that I must use the 'os.' prefix...):
----------------------------------------------------------------------
Help on function spawnv:
spawnv(mode, file, args)
spawnv(mode, file, args) -> integer
Execute file with arguments from args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it.
----------------------------------------------------------------------
Thanks,
--
Godoy. <godoy at metalab.unc.edu>
More information about the Python-list
mailing list