threads and os.spawnlp on Linux

R

Ram

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
 
R

Ram

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,240
Latest member
pashute

Latest Threads

Top