Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22243

Slow termination of process

From Roland Hedberg <roland@catalogix.se>
Subject Slow termination of process
Date 2012-03-27 15:03 +0200
Newsgroups comp.lang.python
Message-ID <mailman.1039.1332855527.3037.python-list@python.org> (permalink)

Show all headers | View raw


Hi!

I have an application/a script that is run from another application.
The script is mostly working as a HTTP client but in some cases it also has to act as a HTTP server.
Basically just for serving a few files. The files are dynamically created by the script when needed.

To accomplish this I'm trying to use subprocess Popen
and an extremely simple web server script which basically contains:

    Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
    httpd = SocketServer.TCPServer((hostname, port), Handler)
    httpd.serve_forever()

In the main script I do:

    op = Popen(popen_args, stdout=PIPE, stderr=PIPE)

When the main script is done it closes down the HTTP server by doing:

    op.terminate()

The problem I have is that if the main script is run again almost immediate then the old HTTP server 
process doesn't seem to have released the port yet. So setting up a new server fails.

Is there anything I can do to get the port released immediately when the tcpserver is terminated.
Or is there another way of doing this that will work better ?

Roland

-----------------------------------------------------------
With anchovies there is no common ground 
-- Nero Wolfe

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Slow termination of process Roland Hedberg <roland@catalogix.se> - 2012-03-27 15:03 +0200

csiph-web