os.system vs os.system inside thread -> why is there any difference?
Jeff Epler
jepler at unpythonic.net
Thu Nov 18 09:28:56 EST 2004
On Thu, Nov 18, 2004 at 12:00:06AM +0100, przemas_r at o2.pl wrote:
> Thanks for the answer.
You're welcome. I'm sorry it didn't work out.
I wrote a pair of standalone programs (no need for arping) to check this
behavior. The bad news is that my program failed on 2.2.2 and 2.3.2.
It only succeed on a CVS version of Python 2.4b2.
To run the test, "python prz.py". It should print "0" twice, because
each time "alarmed.py" should exit from within the SIGALRM signal
handler. On 2.2 and 2.3, it prints "0" (works in the main thread) then
"1" (doesn't work in another thread)
Jeff
Subprogram "alarmed.py":
#------------------------------------------------------------------------
#!/usr/bin/python
import signal, time, sys, os
signal.signal(signal.SIGALRM, lambda *args: sys.exit(0))
os.kill(os.getpid(), signal.SIGALRM)
sys.exit(1)
#------------------------------------------------------------------------
Main program "prz.py":
#------------------------------------------------------------------------
import threading
import os
import signal
def system(s):
p = os.fork()
if p == 0:
os.execvp("/bin/sh", ['sh', '-c', s])
os._exit(99)
else:
p, status = os.waitpid(p, 0);
return os.WEXITSTATUS(status)
class T(threading.Thread):
def run(self):
print system("python alarmed.py")
t = T()
t.run()
t = T()
t.start()
t.join()
#------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041118/d840a5a7/attachment.sig>
More information about the Python-list
mailing list