Slow termination of process

R

Roland Hedberg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top