threads and os.spawnlp on Linux

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ram

    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.Threa d.__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

    #2
    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.Threa d.__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

    Comment

    Working...