os.system vs os.system inside thread -> why is there any difference?

przemas_r at o2.pl przemas_r at o2.pl
Thu Nov 18 13:58:09 EST 2004


I've tested the code you sent. Obviously the result was the one, you 
reffered to as python 2.2.2 or 2.3.2 specific.
Ok, so it's high time I switched to new 2.4.x release.

Thanks again for clarifying me this issue.


Jeff Epler wrote:
> 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()
> #------------------------------------------------------------------------



More information about the Python-list mailing list