Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   threads and os.spawnlp on Linux (http://www.velocityreviews.com/forums/t319036-threads-and-os-spawnlp-on-linux.html)

Ram 06-30-2003 08:37 PM

threads and os.spawnlp on Linux
 
Hi,

The following small script has a child thread which restart the network on a
Linux system. The problem is it never seems to return from the os.spawnlp.
It executes some portions of the network script and then hangs.

If the os.spawnlp is executed in the main thread, it works fine and there is
no problem at all.

os.system also has the same effect as os.spawnlp. Making the thread as a
daemon also has the same effect.

import os
import threading

class Child(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
os.spawnlp(os.P_WAIT, "/etc/init.d/network", "network", "restart")

if __name__ == '__main__':
t = Child()
t.start()

Any ideas of what could be wrong here?

Thanks in advance
Ram

Ram 07-01-2003 04:31 PM

Re: threads and os.spawnlp on Linux
 
Some more info to add on ... the problem seems that if some system
call fails (or times out) in the os.system or os.spawnlp, then it
never returns back the execution context.

The following also causes similar results as before if the IP address
pinged is unreachable, but if it is a reachable IP, it returns
correctly. The problem occurs only if the os.system is inside the
thread class.

import os
import threading
import time

class Child(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
# Pinging some unreachable IP
os.system("ping -c 2 192.168.1.55")
print "done"

if __name__ == '__main__':
t = Child()
t.start()

Thanks
Ram


All times are GMT. The time now is 05:55 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.