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


Groups > comp.lang.python > #22243 > unrolled thread

Slow termination of process

Started byRoland Hedberg <roland@catalogix.se>
First post2012-03-27 15:03 +0200
Last post2012-03-27 15:03 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#22243 — Slow termination of process

FromRoland Hedberg <roland@catalogix.se>
Date2012-03-27 15:03 +0200
SubjectSlow termination of process
Message-ID<mailman.1039.1332855527.3037.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web