[svn r37444] a try at a wrapping loop_socketserver.py

that restarts the actual socketserver.py

--HG--
branch : trunk
This commit is contained in:
hpk 2007-01-27 19:57:05 +01:00
parent 3d70646122
commit 6d403d4573
2 changed files with 15 additions and 3 deletions

View File

@ -0,0 +1,12 @@
import os, sys
if __name__ == '__main__':
directory = os.path.dirname(os.path.abspath(sys.argv[0]))
script = os.path.join(directory, 'socketserver.py')
while 1:
cmd = "python %s %s" % (script, " ".join(sys.argv[1:]))
print "starting subcommand:", cmd
f = os.popen(cmd)
for line in f:
print line,

View File

@ -53,8 +53,8 @@ def bind_and_listen(hostport):
old = fcntl.fcntl(serversock.fileno(), fcntl.F_GETFD) old = fcntl.fcntl(serversock.fileno(), fcntl.F_GETFD)
fcntl.fcntl(serversock.fileno(), fcntl.F_SETFD, old | fcntl.FD_CLOEXEC) fcntl.fcntl(serversock.fileno(), fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)
# allow the address to be re-used in a reasonable amount of time # allow the address to be re-used in a reasonable amount of time
if os.name == 'posix' and sys.platform != 'cygwin': #if os.name == 'posix' and sys.platform != 'cygwin':
serversock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) serversock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversock.bind(hostport) serversock.bind(hostport)
serversock.listen(5) serversock.listen(5)
@ -83,5 +83,5 @@ if __name__ == '__main__':
else: else:
hostport = ':8888' hostport = ':8888'
serversock = bind_and_listen(hostport) serversock = bind_and_listen(hostport)
startserver(serversock, loop=True) startserver(serversock, loop=False)