SOAPpy port reuse

M

Maurice LING

Hi,

I have a problem:

1. Assuming that my application is a SOAP server that uses SOAPpy,
2. I am given port 35021 for use.

What I normally do (simply) is:

functionlist = [<some exposed functions>]
import SOAPpy
server = SOAPpy.SOAPServer((<some host>, 35021))
for func in functionlist: server.registerFunction(func)
server.serve_forever()

My question is: How can I shutdown this server and reuse port 35021 when
my functionlist changes?

Currently, after killing the python process which runs this SOAP server,
the port (35021 in this case) cannot be re-used, as though it is still
phantom-ly bounded to some process (which should have been killed).

Thanks in advance.

Cheers
maurice
 
D

Diez B. Roggisch

Maurice said:
Hi,

I have a problem:

1. Assuming that my application is a SOAP server that uses SOAPpy,
2. I am given port 35021 for use.

What I normally do (simply) is:

functionlist = [<some exposed functions>]
import SOAPpy
server = SOAPpy.SOAPServer((<some host>, 35021))
for func in functionlist: server.registerFunction(func)
server.serve_forever()

My question is: How can I shutdown this server and reuse port 35021 when
my functionlist changes?

Currently, after killing the python process which runs this SOAP server,
the port (35021 in this case) cannot be re-used, as though it is still
phantom-ly bounded to some process (which should have been killed).

It shouldn't be that way. Either you still have some process lying
around hogging the port. Or the OS needs a while to re-enable the port
for allocation. That happened to me quite a few times.

Shutting down gracefully might speed up things I guess.

Diez
 
M

Maurice LING

Diez said:
Maurice said:
Hi,

I have a problem:

1. Assuming that my application is a SOAP server that uses SOAPpy,
2. I am given port 35021 for use.

What I normally do (simply) is:

functionlist = [<some exposed functions>]
import SOAPpy
server = SOAPpy.SOAPServer((<some host>, 35021))
for func in functionlist: server.registerFunction(func)
server.serve_forever()

My question is: How can I shutdown this server and reuse port 35021
when my functionlist changes?

Currently, after killing the python process which runs this SOAP
server, the port (35021 in this case) cannot be re-used, as though it
is still phantom-ly bounded to some process (which should have been
killed).

It shouldn't be that way. Either you still have some process lying
around hogging the port. Or the OS needs a while to re-enable the port
for allocation. That happened to me quite a few times.

Shutting down gracefully might speed up things I guess.

I am under the impression that SOAPpy.SOAPServer.serve_forever() is an
"endless" loop. I had been suggested to see if there is a method of
SOAPpy.SOAPServer (which I can call through a wrapper function in
functionlist) that can enable me to gracefully shutdown the server.

Any advice?

Thanks
Maurice
 
P

Piet van Oostrum

Maurice LING said:
ML> Hi,
ML> I have a problem:
ML> 1. Assuming that my application is a SOAP server that uses SOAPpy,
ML> 2. I am given port 35021 for use.
ML> What I normally do (simply) is:
ML> functionlist = [<some exposed functions>]
ML> import SOAPpy
ML> server = SOAPpy.SOAPServer((<some host>, 35021))
ML> for func in functionlist: server.registerFunction(func)
ML> server.serve_forever()
ML> My question is: How can I shutdown this server and reuse port 35021 when my
ML> functionlist changes?
ML> Currently, after killing the python process which runs this SOAP server,
ML> the port (35021 in this case) cannot be re-used, as though it is still
ML> phantom-ly bounded to some process (which should have been killed).

This phenomenon is explained here:
http://hea-www.harvard.edu/~fine/Tech/addrinuse.html
or the Unix socket FAQ (http://www.faqs.org/faqs/unix-faq/socket/) 2.7

Normally the solution is to set the SO_REUSEADDR option in the socket (the
original one) before binding it:
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)

However, SOAPPy does that already so it should work.
 
G

Gabriel Genellina

I am under the impression that SOAPpy.SOAPServer.serve_forever() is an
"endless" loop. I had been suggested to see if there is a method of
SOAPpy.SOAPServer (which I can call through a wrapper function in
functionlist) that can enable me to gracefully shutdown the server.

serve_forever is inherited from SocketServer.BaseServer and it's just an
infinite loop calling self.handle_request() over and over.
You have to break out of the loop somehow and call self.server_close().
Something like this (untested):

def serve_forever(self):
while not self.some_flag_to_indicate_it_has_to_stop:
self.handle_request()
self.server_close()
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top