Signal SIGINT ignored during socket.accept

James Harris james.harris.1 at
Thu Sep 10 22:12:40 CEST 2015

"Chris Angelico" <rosuav at> wrote in message 
news:mailman.337.1441913195.8327.python-list at
> On Fri, Sep 11, 2015 at 5:11 AM, James Harris 
> <james.harris.1 at> wrote:


>> However, on Windows the recognition of Control-C does not happen 
>> until after
>> something connects to the socket.


> This is a known problem on Windows.


> It's entirely possible that a blocking socket-accept call will
> continue to block. There is one rather silly option, and that's to use
> select() to effectively poll for Ctrl-C... or, possibly better, have a
> separate program that shuts down your server (by connecting to it,
> which thus breaks the stranglehold).

Thanks for your help, Chris. Using select() is a very good option. I 
tried first without a timeout and even then this version of Windows does 
not recognise Control-C until after the select() call returns (which 
needs similar prompting as with the accept() call. However, select() 
with a timeout allows the code to work both on Windows and Linux. 

For anyone else who is looking for this the earlier test code was 
changed to

port = 8880
import select
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", port))
while 1:
  ready =,), (), (), 0.5)
  #print '(ready %s)' % repr(ready)
  if (ready[0]):
      endpoint = s.accept()
    except socket.error, details:
      print 'Ignoring socket error:', repr(details)
    print '(endpoint %s)' % repr(endpoint)
    if endpoint:


More information about the Python-list mailing list