I HAVE THIS PYTHON PROGRAMM:
[test]$ cat socpb.py
import BaseHTTPServer, SocketServer, os, socket, threading
# the server initialisation
server = SocketServer.TC PServer((socket .gethostname(),
8088),BaseHTTPS erver.BaseHTTPR equestHandler)
t=threading.Thr ead(target=serv er.serve_foreve r)
t.setDaemon(1)
t.start()
# the command
os.system("slee p 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.TC PServer((socket .gethostname(),
8088),BaseHTTPS erver.BaseHTTPR equestHandler)
File "/usr/local/lib/python2.3/SocketServer.py ", line 330, in __init__
self.server_bin d()
File "/usr/local/lib/python2.3/SocketServer.py ", line 341, in
server_bind
self.socket.bin d(self.server_a ddress)
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 ?
Comment