KeyboardInterrupt catch does not shut down the socketserver

Igor Katson descentspb at gmail.com
Sun May 17 10:20:33 CEST 2009


Gabriel Genellina wrote:
> En Sat, 16 May 2009 04:04:03 -0300, Igor Katson <descentspb at gmail.com> 
> escribió:
>> Gabriel Genellina wrote:
>>> En Fri, 15 May 2009 09:04:05 -0300, Igor Katson escribió:
>>>> Lawrence D'Oliveiro wrote:
>>>>> In message <mailman.185.1242375959.8015.python-list at python.org>, 
>>>>> Igor Katson wrote:
>>>>>> Lawrence D'Oliveiro wrote:
>>>>>>> In message <mailman.183.1242371089.8015.python-list at python.org>, 
>>>>>>> Igor Katson wrote:
>>>>>>>
>>>>>>>> I have problems in getting a SocketServer to shutdown.
>>>> Shutdown implies closing the listening socket, doesn't it?
>>>
>>> No (perhaps it should, but that is another issue). There is a
>>> documentation bug; BaseServer.shutdown is documented as "Tells the
>>> serve_forever() loop to stop and waits until it does." [1]
>>> The docstring is much more explicit: """Stops the serve_forever loop.
>>> Blocks until the loop has finished. This must be called while
>>> serve_forever() is running in another thread, or it will deadlock."""
>>>
>>> So, if you have a single-threaded server, *don't* use shutdown(). 
>>> And, to orderly close the listening socket, use server_close() 
>>> instead. Your
>
>> Hmm. Gabriel, could you please show the same for the threaded 
>> version? This one deadlocks:
>> [code removed]
>
> The shutdown method should *only* be called while serve_forever is 
> running. If called after server_forever exited, shutdown() blocks 
> forever.
>
> [code removed]
> But, what are you after, exactly? I think I'd use the above code only 
> in a GUI application with a background server.
> There are other alternatives, like asyncore or Twisted.
For now, I am just using server.server_close() and it works. The server 
itself is an external transaction manager for PostgreSQL, when a client 
connects to it, serialized data interchange beetween the server and the 
client starts, e.g. first the client sends data, then the server sends 
data, then again the client, then the server and so on.
I haven't used asyncore or Twisted yet, and didn't know about their 
possible usage while writing the project. I'll research in that direction.




More information about the Python-list mailing list