socket and os.system




I HAVE THIS PYTHON PROGRAMM:


[test]$ cat socpb.py
import BaseHTTPServer, SocketServer, os, socket, threading


# the server initialisation
server = SocketServer.TCPServer((socket.gethostname(),
8088),BaseHTTPServer.BaseHTTPRequestHandler)
t=threading.Thread(target=server.serve_forever)
t.setDaemon(1)
t.start()


# the command
os.system("sleep 3600")
[test]$






I LAUNCH IT:


[test]$ python socpb.py


[1]+ Stopped python socpb.py
[test]$ bg
[1]+ python socpb.py &






I LOOK THE PORT IT USE --> OK:


[test]$ netstat -taupe | grep 8088
tcp 0 0 test:8088 *:* LISTEN mik 32481 14092/python






I KILL THE PYTHON PROGRAMM (OR IT STOP BY ANOTHER WAY):


[test]$ kill 14092
[test]$
[1]+ Terminated python socpb.py






I LOOK THE PORT --> NOK, I EXPECTED THAT THE PORT WAS FREED BUT SLEEP
IS LISTENING AND IF I TRY TO LAUNCH MY PROGRAMM, IT FAIL:


[test]$ netstat -taupe | grep 8088
tcp 0 0 test:8088 *:* LISTEN mik 32481 14094/sleep
[test]$ python socpb.py
Traceback (most recent call last):
File "socpb.py", line 4, in ?
server = SocketServer.TCPServer((socket.gethostname(),
8088),BaseHTTPServer.BaseHTTPRequestHandler)
File "/usr/local/lib/python2.3/SocketServer.py", line 330, in __init__
self.server_bind()
File "/usr/local/lib/python2.3/SocketServer.py", line 341, in
server_bind
self.socket.bind(self.server_address)
File "<string>", line 1, in bind




socket.error: (98, 'Address already in use')




IF I KILL THE SLEEP, ALL COME BACK FINE:


[test]$ kill 14094
[test]$ netstat -taupe | grep 8088
[test]$ python socpb.py








I HAVE SEARCHED ON THE WEB HOW TO LAUNCH THE SLEEP WHITHOUT IT GET THE
PORT IN THE ENVIRONNEMENT BUT NOTHING...


I HAVE A WORKAROUND BY USING rsh BUT I AM NOT VERY PLEASED WITH THAT.


DOES SOMEONE HAS AN IDEA ?











.



Relevant Pages

  • Re: Thread killing - I know I know!
    ... I'm not sure it's possible to kill a thread in Python that's in the middle ... I'm on Windows and signals isn't fully implemented. ... for killing processes, ...
    (comp.lang.python)
  • Re: Thread killing - I know I know!
    ... I'm not sure it's possible to kill a thread in Python that's in the middle ... I'm on Windows and signals isn't fully implemented. ... for killing processes, ...
    (comp.lang.python)
  • Re: thread, threading; how to kill a thread?
    ... Python is embedded into C++. ... I was able to kill the threads ... nThreadId is the ID of the thread that you want to terminate (i.e. ... Calling this function will cause an exception to ...
    (comp.lang.python)
  • Re: How can I kill a running thread when exiting from __main__
    ... I have written a short Python server ... hints on how to cleanly kill running threads before exiting. ... class QueueThread(threading.Thread): ... There have been many suggestions to allow external forced termination of threads, but this is impossible to specify in a clean way that is both platform-independent and reliable, so it's not likely to happen. ...
    (comp.lang.python)
  • thread, threading; how to kill a thread?
    ... forked heavyweight multi-processing apps. ... Using Python 2.3.3 on a Redhat 7.x machine. ... Wondering if there is a simple way from a main python program to kill ... delon the thread object that's running the loop function ...
    (comp.lang.python)